Response.BinaryWrite()下载时文件名的问题.
我们经常将文件上传到数据库中,比如Sql Server中.
然后在下载的时候,用的比较多的也就是Response.BinaryWrite()方法,然而如果直接输出的话,其文件名总是为你的页面的文件名,如downLoadFile.aspx.
其解决方法为:
然后在下载的时候,用的比较多的也就是Response.BinaryWrite()方法,然而如果直接输出的话,其文件名总是为你的页面的文件名,如downLoadFile.aspx.
其解决方法为:
1 Page.Response.Buffer=true;
2 Page.Response.Clear();
3 //这里的ContentType也可以读存入数据库中的文件类型.
4 Page.Response.ContentType="Application/unknown";
5 //attachment是以附件的形式下载,也可以改为online在线找开.
6 Response.AddHeader("Content-Disposition","attachment; filename=" +
7 ds.Tables[0].Rows[0]["filename"].ToString() + ";");
8
9 Page.Response.BinaryWrite(file);
10 Page.Response.Flush();
11 Page.Response.End();
2 Page.Response.Clear();
3 //这里的ContentType也可以读存入数据库中的文件类型.
4 Page.Response.ContentType="Application/unknown";
5 //attachment是以附件的形式下载,也可以改为online在线找开.
6 Response.AddHeader("Content-Disposition","attachment; filename=" +
7 ds.Tables[0].Rows[0]["filename"].ToString() + ";");
8
9 Page.Response.BinaryWrite(file);
10 Page.Response.Flush();
11 Page.Response.End();