读书人

文件下载 .

发布时间: 2011-12-24 23:03:24 作者: rapoo

文件下载 在线等.....
string LocalPath= "H:/ERPtest_FTP/ "+TheFtpType+ "/ "+Theremotepath+ "/ ";
stringTheName=LocalPath+LocalFileName;
string TN=LocalFileName;
string TT= "Content-Disposition ";
string TV= "attachment;filename= "+HttpContext.Current.Server.UrlEncode(Request.QueryString[ "strFilename "].ToString());

Response.AddHeader(TT,TV);
Response.WriteFile(TheName);

用如上代码下载。当格式为PDF文件时,下载下来的总比原来文件大约2K。所以打开会出错。但JPG,Xls不会。
请问怎么解决。
在线等.....

[解决办法]
没下过PDF的。帮顶一下吧!
[解决办法]
在你自己的代加入一句:
Response.AddHeader( "Content-Length ", DownloadFile.Length.ToString()););

或用方式:
private void FileDownload()
{
String FullFileName = Server.MapPath( "文件路径 ");
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader( "Content-Length ", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}

[解决办法]
穷得只剩下帮顶了

读书人网 >asp.net

热点推荐