如何从sql server数据库下载.pdf / .txt / .jpeg。 [英] How to Download a .pdf/.txt/.jpeg from sql server database.

查看:61
本文介绍了如何从sql server数据库下载.pdf / .txt / .jpeg。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想设计一个usercontrol,用户可以上传文件(.pdf / .txt / .jpeg) - 我是能够使用FileUpload控件构建,但我的问题是如何构建一个控件,用户可以看到上传文件的列表,然后单击它下载它。我正在使用Linq2Sql,并且有一个表格,其列为Asset [],用于存储上传的文件。



我需要样本标记和代码隐藏,这可以帮助我实现这个。



谢谢,



Chetan。

Hi,

I want to design a usercontrol where the user will be able to upload a file(.pdf/.txt/.jpeg)-which i was able to build using FileUpload control, but my problem is how to build a control where the user can see a list of uploaded file and click on it to download it. I am using Linq2Sql and have a table with a column Asset as byte[] to store the uploaded files.

I need sample Markup and Code Behind that can help me achieve this.

Thank you,

Chetan.

推荐答案

从数据库读取字节并使用Response.BinaryWrite向下发送文件,确保也设置标题。



You read the bytes from the DB and use Response.BinaryWrite to send the file down, making sure you set the header as well.

Response.ClearContent()
                  Response.ClearHeaders()
                  Response.AddHeader("Content-Length", b.Length.ToString)
                  Response.ContentType = ContentType
                  Response.BinaryWrite(b)
                  Response.Flush()
                  Response.Clear()





类似的东西,其中b是你的字节数组。



Something like that, where b is your array of bytes.


我能够在文件上传中设计表格为谁编写代码
i able to design the form in file upload who to write code for it


这篇关于如何从sql server数据库下载.pdf / .txt / .jpeg。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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