打开文件时文件名乱码,另存为是好的,为何?在线等啊!
请教大虾们,这是怎么回事了,搞了一天都没搞定:上传时:
entity.RESOURCENAME = fileAcceptAttached.PostedFile.FileName;
entity.DOCDNAME = fileAcceptAttached.FileName;
。。。
读取时:
byte[] bytFileContent = 。。
Response.Buffer = true;
Response.Clear();
Response.Charset = "GB2312";
Response.ContentType = "application/octet-Stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename));
Response.AddHeader("Content-Length", bytFileContent.Length.ToString());
Response.BinaryWrite(bytFileContent);
Response.Flush();
另存为时文件名好好的,但直接打开就不行了,怎么改啊?!
------解决方案--------------------HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + SaveFileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", myFile.Length.ToString());
------解决方案--------------------编码问题。换编码试试
------解决方案--------------------Server.UrlEncode("你的文件名");