2017-10-16 191 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"); 

我的错 - 我没有在我的数据库中包含文件扩展名 感谢您的评论!