2011-08-06 101 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

謝謝你這麼多戈文德... –

相關問題