开发者

Download a file stored in database

I have file content in sql database as binary format and also saved the file with its extension .

I want to have pop up for save as ,so that client can save the file on her system in the same 开发者_运维技巧document format.

i.e if it .doc then it should get save in .doc format only.

Please provide the code for the same.


You need to

  1. Set up IIS to to handle files of the types you want. For example, you need to map .pdf, .jpg, etc, to be handled by the ASP.net dll. Also is important to make sure "Verify file exists" is off: http://msdn.microsoft.com/en-us/library/bb515343.aspx
  2. Create a HTTP Handler for the files to retrieve the binary from the database and .BinaryWrite it out to the output stream: http://www.developer.com/net/asp/article.php/3565541/Use-Custom-HTTP-Handlers-in-Your-ASPNET-Applications.htm
  3. Set up your web.config file to map the file types required to the handler you created (this is detailed in the url provided for point 2)
  4. You say that you want it to open as a download box, and not just open in the browser. To do this you have to use the content-disposition HTTP header. So in your custom handler you write, make sure to add a header specifiying the content-disposition as attachment. http://support.microsoft.com/kb/260519 will tell you what you need.

I want to have pop up for save as ,so that client can save the file on her system in the same document format.

i.e if it .doc then it should get save in .doc format only.

You take care of this when you write out the content disposition HTTP header. Refer to the MS link I provided and make sure you specify a filename with the correct extension.

Also note the comments above. If this helps you, you need to accept it as the answer. Also go back and accept some answers on your older questions. Otherwise people are not inclined to help you. I will help you again if you mark this as answer, or leave me a comment about why it does not answer your question.

Good luck

bgs264

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜