我只是将上传的文件存储到 SQL Server 中的二进制字段中,但我还需要允许用户使用 Asp.NET 下载它。我怎样才能做到这一点?
提前致谢。
最佳答案
Here's a Microsoft Knowledge Base article on this.
如何从数据库检索文件取决于您使用的数据访问技术;我假设您有一些包含文件的字节数组data
(例如,通过填充数据集并访问字段)和一些字符串filename
。
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment;filename=""" & filename & """")
Response.BinaryWrite(data)
Response.End()
将上述代码放入 download.aspx
中并链接到该文件。您可能希望将一些查询字符串信息传递到 download.aspx,以便您的代码知道从数据库获取哪个文件。
关于asp.net - 如何下载以二进制格式存储在 SQL DB 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1902421/