Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
Hi guys,

I have a load of files of all different types (Word documents, PDFs, zips, etc) stored in the database.

My client wants it so that when he clicks on a HTML link, it retrieves the specified file
from the database and opens it using the default program for that file type.

Now here's the problem. I can easily retrieve the file from the DB, but I cannot write it to the local directory due to security restrictions on the web server itself. There's another local drive (D:/) that I can write the file to perfectly fine, but most modern browsers prevent you from opening a link like the following:
JavaScript
window.open('file:///D:/Temp/tmp1.docx');

And:
JavaScript
<a href="file:///D:/Temp/tmp1.docx">file link</a>

And for good reason.

So what would be the best way of automatically opening a file like this directly from the DB?

Many thanks in advance.
Posted
Comments
Prasad Khandekar 30-Apr-13 6:14am    
Hello Nick,

You will have to stream the file back to browser. You may have to develop an handler to stream the file back. There are many articles available on this site. Just search for File Streaming. One that might of interest to you is this article (http://www.codeproject.com/KB/cs/SimpleZip.aspx)

Regards,
Nick Fisher (Consultant) 30-Apr-13 6:46am    
Hi,

Yes, thanks for your answer. Having looked into it further, I think I can get it open on the client side by writing the byte stream directly to the repsonse, then setting the Response.ContentType to "application/octet-stream". I have not got it working yet, but I'm nearly there. Many thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900