如何以二进制格式下载存储在SQL DB中的文件 [英] How to Download A file stored in SQL DB in Binary Format
问题描述
提前感谢
如何从数据库中检索文件取决于您使用的数据访问技术;我只会假设你有一些包含文件的字节数组(例如填充DataSet和访问字段)和一些字符串 filename
code>。
Response.Clear()
Response.ContentType =application / octet-stream
Response.AddHeader(Content-Disposition,attachment; filename =& filename&)
Response.BinaryWrite(data)
Response.End )
将上述代码放在一些 download.aspx
并链接到此文件。您可能希望将一些查询字符串信息传递给您的download.aspx,以便您的代码知道从数据库获取哪个文件。
I am simply storing uploaded file into a binary field in SQL Server but I also need to allow users to download it with Asp.NET. How can I do that ?
Thanks in advance.
Here's a Microsoft Knowledge Base article on this.
How to retrieve the file from your database depends on the data access technology you use; I will just assume that you have some Byte array data
containing the file (e.g. by filling a DataSet and accessing the field) and some string filename
.
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment;filename=""" & filename & """")
Response.BinaryWrite(data)
Response.End()
Put the above code in some download.aspx
and link to this file. You probably want to pass some query string information to your download.aspx, so that your code knows which file to get from the database.
这篇关于如何以二进制格式下载存储在SQL DB中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!