How to force the download a file from a network share rather than editing the file there

3.8k views Asked by At

I have a web page that is hosted in our local network. On my page I have a link to a document. The document is linked to a network share. If the user opens the file, edits it and then goes to save the file it overwrites what is on the share. When opening the file I want the user to download the file, so when they come to save it they do not have the option to save it back. How could I go about doing this?

Server side I have access to asp.

3

There are 3 answers

0
Antony Scott On

You need to create a link which when clicked, streams the contents of the file to the browser, rather than having a link to the files actual location. If you do this the user will be prompted to save the file somewhere locally.

I am not at my PC currently so cannot get you an example piece of code, but you need to send the response with the content type set appropriately. Look in to mime types for a pointer in the right direction.

0
AnthonyWJones On

The term "download" is misunderstood here. When we open windows explorer and copy a file from a network share to our local machine don't think it terms of "downloading" it, we are just copying it. To "download" usually refers to access some resource outside of our local network and pulling that resource into that network.

Hence to achieve your aim you need to convince the client that is not accessing a file that is a local network resource. You can do this by adding a Virtual Folder to the IIS site that points the appropriate folder in the network share. Change the URL to use a "http:" protocal pointing at the virtual folder in your site.

Now the users will get the file from your website rather than accessing it as a normal file on the network.

0
Jason On

You can stream the file through a webpage to download the file instead of opening a network share.

See this for an example:

http://support.microsoft.com/kb/276488

You can also share a directory through your web server by enabling directory browsing.

IIS 6: http://blog.crowe.co.nz/archive/2006/03/18/603.aspx

IIS 7: http://technet.microsoft.com/en-us/library/cc731109(WS.10).aspx