Click here to Skip to main content
11,790,366 members (61,566 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Javascript HTML , +
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:'file:///D:/Temp/tmp1.docx');
<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 29-Apr-13 23:27pm
Prasad Khandekar at 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 (

Nick Fisher (Consultant) at 30-Apr-13 6:46am

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)

  Print Answers RSS
0 OriginalGriff 315
1 ppolymorphe 219
2 Richard MacCutchan 158
3 Jochen Arndt 95
4 Maciej Los 90
0 OriginalGriff 1,114
1 Maciej Los 825
2 KrunalRohit 686
3 CPallini 611
4 ppolymorphe 610

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100