如何以二进制格式下载存储在SQL DB中的文件 [英] How to Download A file stored in SQL DB in Binary Format

查看:136
本文介绍了如何以二进制格式下载存储在SQL DB中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是将上传的文件存储到SQL Server的二进制字段中,但是我也需要允许用户使用Asp.NET进行下载。如何做?



提前感谢

解决方案

这是Microsoft知识库文章。



如何从数据库中检索文件取决于您使用的数据访问技术;我只会假设你有一些包含文件的字节数组(例如填充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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆