处理德国人物

时间:2013-11-01 20:03:51

标签: c# asp.net localization

我正在构建一个页面来管理上传到服务器的文件。

有些客户上传的文件包含含有晦涩德语字符的文件名。 尽管中文字符没有问题,但系统似乎无法正确阅读这些内容!

文件名1:1--Referenz Frau Strauß.docx

系统看到了什么:1--Referenz Frau Strauß.docx

这是我的代码:

protected void gvFiles_RowDeleting(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    GridViewRow row = (GridViewRow)btn.NamingContainer;

    TableCell cell = row.Cells[0];
    string fName = cell.Text;
    cell = row.Cells[1];
    string owner = cell.Text;
    if (owner == "-")
    {
        string filePath = "";
        filePath = getFilePath();
        string path = filePath + fName;
        if (File.Exists(path))
        {
            File.Delete(path);
        }
    }
    postbackProc();
}

有问题的字段是cell.Text。它正确显示在屏幕上,但找不到文件。

我从服务器获取文件名:

private void GetFilesFromDirectory(string DirPath)
{
    try
    {
        DirectoryInfo Dir = new DirectoryInfo(DirPath);
        //Label1.Visible = true;
        lblPath.Visible = true;
        lblPath.Text = DirPath;
        FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories );
        DataTable dt = new DataTable("File_List");
        DataRow dr;
        int iRow = 0;
        dt.Columns.Add("refFileName", typeof(String));
        dt.Columns.Add("Owner", typeof(String));
        foreach (FileInfo FI in FileList )
            {
                iRow++;
                dr = dt.NewRow();
                dr["refFileName"] = FI.Name;
                dr["Owner"] = getFileData(FI.Name);
                dt.Rows.Add(dr);           
            }
        gvFiles.DataSource = dt.DefaultView;
        gvFiles.DataBind();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

任何解决方案?

1 个答案:

答案 0 :(得分:1)

我只能想象你有使用utf-8

的问题

确保您的所有服务器端文件(.aspx,.ascx,.html,.cshtml ..等)全部使用(另存为,带编码,utf-8 ..带或不带bom)< / p>

另请检查您的web.config以获取正确的utf处理

<system.web>
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" responseHeaderEncoding="utf-8" fileEncoding="utf-8" />
</system.web>
相关问题