日期:2014-05-20  浏览次数:20441 次

文件下载 在线等.....
string   LocalPath= "H:/ERPtest_FTP/ "+TheFtpType+ "/ "+Theremotepath+ "/ ";
string TheName=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();
}

------解决方案--------------------
穷得只剩下帮顶了