Click here to Skip to main content
Rate this: bad
good
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:
	window.open('file:///D:/Temp/tmp1.docx');
And:
	<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 30-Apr-13 0:27am
Comments
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 (http://www.codeproject.com/KB/cs/SimpleZip.aspx)
 
Regards,
Nick Fisher (Consultant) at 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)

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


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