tags:

views:

551

answers:

4

I'd like to redirect the user to a directory on a file server using its UNC path. I've tried using something like the following but I just get a 404 error.

Response.Redirect(@"file:\\fileserver\data\");

What's the correct syntax to make this work?

A: 

I'm not sure about the Response.Redirect method, but you can always write the file for download by the user using Response.WriteFile.

This link might help: http://support.microsoft.com/kb/307603/EN-US/

Code Snippet from above link:

private void Page_Load(object sender, EventArgs e)
{
   //Set the appropriate ContentType.
   Response.ContentType = "Application/pdf";
   //Write the file directly to the HTTP output stream.
   Response.WriteFile(@"\\server\folder\file.pdf");
   Response.End();
}
bendewey
The question was about redirecting to a directory, rather than a file. Not sure your code snippet and example would work as is.
Scott Ferguson
+1  A: 

You don't quite have the file protocol identifier correct. Try:

string location = String.Format("file:///{0}", @"\\fileserver\data\");
Response.Redirect(location, true);
Scott Ferguson
I tried this but still get a page cannot be displayed error in IE7. Could this be a browser security thing? I tried viewing the page in FF3 and get the message "Object moved here". I have not idea, when I simply type the UNC path into the browser it works fine, isn't that essentially what a redirect does?
joshb
That depends what error you're getting. 404 isn't a security thing, it's just a file not found. What Html Error code are you getting?
Scott Ferguson
Not really sure what type of error. IE just says "Internet Explorer cannot display the webpage". I inspected the header in FF3 and it seems to be sending the correct 302 to the right location.
joshb
A: 

file:////server/directory

Or, create a virtual directory in your Website and map it to a path, like /data/

Chad Grant
A: 

Do the people on your webapp have access to this UNC path?

tsilb