2011-08-06 69 views

回答

2

我认为您的解决方案是:

Response.ContentType = "application/ms-excel"; 
Response.AddHeader("content-disposition", "attachment; filename=CSVhhID" + Uid + ".csv"); 
string newpath2 = System.Web.HttpContext.Current.Server.MapPath("~//downloadfile//CSVID" + Uid + ".csv"); 
FileStream sourceFile = new FileStream(newpath2, FileMode.Open); 
long FileSize; 
FileSize = sourceFile.Length; 
byte[] getContent = new byte[(int)FileSize]; 
sourceFile.Read(getContent, 0, (int)sourceFile.Length); 
sourceFile.Close(); 
+0

感谢它也可以..... –

2

用户此技术。

string filePath = Server.MapPath("~/files/myFileName.csv"); 
    System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); 
    Response.ContentType = "application/octet-stream"; 
    Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\\\"{0}\\\"", filePath)); 
    Response.AddHeader("Content-Length", fileInfo.Length.ToString()); 
    Response.WriteFile(filePath); 
    Response.End(); 
+1

谢谢你这么多戈文德... –

相关问题