1

I want to open Documents from Shared Folder on network using ASP.NET with C#. My situation as follow:

  1. My Web Server Name is “WebServer1” use IIS 7
  2. My DC Server Name is “DC1”
  3. My File Server Name “FileServer1”
  4. My Files Path \\FileServer1\A\B\C\MyDoc.docx and \\FileServer1\A\B\C\MyPDF.pdf

I tried the following

1- I Created Hyper Link

<a href="file:///// FileServer1\A\B\C\MyDoc.docx" target="_blank">link to file</a> 

The files open on some machines that uses Internet Explorer version 8 but on any other version or Chrome, Fire Fox, or any other web browser it doesn't work when I click on the hyper link no action happens and no errors, but if I copied the link address and pasted it into the web browser the file opens

I gave the path in the file server full control permission for “everyone”

2- I also tried to create a button with the following code

Response.ContentType = 
    "application/vnd.openxmlformats- officedocument.wordprocessingml.document";
Response.AppendHeader("Content-Disposition", "attachment; filename=5401-1-2289.docx");
Response.Redirect("file:///// FileServer1\A\B\C\MyDoc.docx");
Response.Flush();
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • The `file:///// ` contains a space after the last `/`, is this correct? – Stefan May 05 '15 at 07:56
  • When using `Content-Disposition: attachment`, you need to write the file to output, not use a `Redirect`. You can use something like `Response.TransmitFile(@"\\FileServer1\A\B\C\MyDoc.docx");` As for the hyperlink/redirect, it would require the user to have access to the shared drive, not the web server. And it only ever works in Outlook / IE / Word etc., by design - http://stackoverflow.com/questions/1369147/linking-a-unc-network-drive-on-an-html-page – Luaan May 05 '15 at 07:56

1 Answers1

0

First of all, the URL is incorrect. It should be @"file://\\FileServer1\A\B\C\MyDoc.docx" instead of "file:///// FileServer1\A\B\C\MyDoc.docx" (I have a hard time thinking this actually compiles, because you didn't escape \...)

Second, you are combining both sending content, as redirecting, as pointed out by Luaan in a comment. This won't work.

You could transmit the file directly. This also prevents you to expose your network drive to external users:

Response.TransmitFile(@"\\FileServer1\A\B\C\MyDoc.docx");
Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • 1
    Actually, `file://///` is the correct prefix - that's the IE convention. But that's still the point - it's only an IE convention, and it only really existed for ActiveDesktop and similar stuff (it's deprecated in IE 9). For security reasons, this isn't supported by browsers anymore. – Luaan May 05 '15 at 08:02
  • Ah, okay. Thanks for pointing that out. Still it is very IE specific and shouldn't be used, so I will keep it in the post. And it shouldn't compile... – Patrick Hofman May 05 '15 at 08:02