Reputation: 3279
I am building a page to manage files uploaded to the server.
Some customers have uploaded files with filenames containing obscure German characters. The system can't seem to read these properly, although it has no problem with Chinese characters!
Filename1: 1--Referenz Frau Strauß.docx
What the system sees: 1--Referenz Frau Strauß.docx
Here is my code:
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();
}
The field in question is cell.Text. It is displaying on screen correctly, but does not find the file.
I am getting the filenames from the server:
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;
}
}
Any solutions?
Upvotes: 1
Views: 1465
Reputation: 2416
I can only imagine you having problems with utf-8
Make sure that your all your server-side files (.aspx, .ascx, .html, .cshtml ..etc) are all with (save as, with encoding, utf-8 ..with or without bom)
Also check your web.config for correct utf handling
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" responseHeaderEncoding="utf-8" fileEncoding="utf-8" />
</system.web>
Upvotes: 1