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

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

问题描述

我只是存储上传文件转换成二进制字段在SQL Server中,但我还需要允许用户使用Asp.NET下载。我该怎么做?

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 ?

先谢谢了。

推荐答案

这里有一个微软这个知识库文章。

如何检索文件从您的数据库取决于您使用的数据访问技术;我只是假设你有一些Byte数组数据包含文件(例如,通过填充DataSet并访问场)和一些字符串文件名

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()

把一些上述code download.aspx 并链接到该文件。你可能想一些查询字符串信息传递给你的download.aspx,让你的code知道从数据库中获取的文件。

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数据库二进制格式的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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