2017-10-16 187 views
-2
protected void getFileAttachment(byte[] bytes) 
{ 
    Response.Clear(); 
    Response.Buffer = true; 
    Response.Charset = ""; 
    Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    Response.ContentType = fileType; 
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + "test101"); 
    Response.OutputStream.Write(bytes,0,bytes.Length); 
    Response.BinaryWrite(bytes); 
    Response.Flush(); 
} 

我想轉換被保存在SQL Server VARBINARY和我有麻煩,因爲輸出文件沒有擴展二進制文件下載 - 但下載的文件沒有文件擴展名?

+2

你的Content-Disposition標題有一個沒有擴展名的文件名 - 如果你希望有一個擴展名,就添加一個。 – jdphenix

+0

您並未添加擴展程序。你期望它來自哪裏? –

+0

謝謝,這是我的錯,我沒有注意到。謝謝帕爾! –

回答

0
Response.AppendHeader("Content-Disposition", "attachment; filename=" + "test101.filetype"); 

我的錯 - 我沒有在我的數據庫中包含文件擴展名 感謝您的評論!