ie6處理下載文件名過長問題的解決方案
瀏覽量:4463
CRM定制,軟件開發(fā),辦公OA 易勢科技是你的好伙伴
今天終于發(fā)現(xiàn),使用gb2312編碼Header就可以使文件名長度限制為75個(gè)中文字符,已經(jīng)基本滿足了需要。就其原理,這是微軟的一個(gè)bug,header長度有限制,好像是158個(gè)字節(jié),如果使用UTF-8編碼文件名,超過18個(gè)中文字符的文件名就會(huì)超過限制,產(chǎn)生文件名亂碼。但是使用gb2312編碼,每個(gè)漢字2個(gè)直接,就可以使中文件名的限制擴(kuò)展到75個(gè)
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.HeaderEncoding = Encoding.GetEncoding("gb2312"); //此處編碼必須為gb2312,文件名最多可有75個(gè)漢字
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileFullName);
FileInfo objFileInfo = new FileInfo(Server.MapPath(strPath + "/" + strFileFullName));
Response.AddHeader("Content-Length", objFileInfo.Length);
Response.WriteFile(Server.MapPath(strPath + "/" + strFileFullName));
Response.Flush();
Response.End();

