Click here to Skip to main content
13,054,779 members (65,402 online)
Rate this:
Please Sign up or sign in to vote.
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 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) 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
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