0

I have documents (images, Word documents, PDF's, etc) stored in an SQL Server database table. On my form, I display the names of these documents and need for the user to be able to click a document title and have the contents retrieved from the database and then opened in the default viewer; Word for example for a Word document.

I'm not sure about the best way to approach this. I tried using an $.ajax call to a web service that queries the database and then write the bytes out to the current context but this doesn't seem to work.

Any tips would be greatly appreciated.

2 Answers 2

2

You can use this approach:

Change the Response.ContentType to the correct type of content being streamed, which you can do by examining the extension of the file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Brian for such a quick response. I'm evaluating them now!
The 3rd article did the trick. Using Response.ContentType = "application/octet-stream" seemed to work well where I didn't have to keep track of the content type.
1

You need to create a generic handler for downloading documents and send document id to this handler via hyperlink in query string parameter. Along with document content you need to store also content type of document like image/jpeg, application/msword etc and send to client with document body. Unfortunatelly I can't find an application for jQuery here so this task left on you.

Check this article for handler creation explanation: http://www.intstrings.com/ramivemula/asp-net/retrieve-files-from-a-table-in-database-using-generic-handler/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.