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等却是正确的。
如何解决??
在线等..........
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等却是正确的。
如何解决??
在线等..........
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();
}//呵呵,樓主同一問題開了兩個帖,估計是不想結帖的。
//但還是幫你^_^