views:

86

answers:

1

I am writing an ASP application that will serve files to clients through the browser. The files are located on a file server that is available from the machine IIS is running on via a UNC path (\server\some\path).

I want to use something like the code below to serve the file. Serving files that are local to the machine IIS is running on is working well with this method, my trouble is being able to serve files from the UNC mapped share:

//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";

//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");

//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();

My question is how I can specify a UNC path for the file name. Also, to access the file share I need to connect with a specific username/password.

I would appreciate some pointers on how I can achieve this (either using the approach above or by other means).

+1  A: 

I'm not an ASP guy so I might be completely wrong with these answers.

Regarding the path, I don't think you should be using MapPath, since that's to get a relative path and you already know the physical path so can't you just change that to:

string FilePath = @"\\Server\Directory\FileName.txt";

Regarding the account, I think you need to use impersonation, this link seems to discuss just this:

http://aspalliance.com/336_Upload_Files_Using_ASPNET_Impersonation_and_UNC_Share.all

ho1
Thanks for the input. The impersonation suggestion got me going in the right direction, and I managed to hunt down the following link http://support.microsoft.com/default.aspx?scid=KB;EN-US;306158 which has a section how I can implement impersonation in a specific section of code within an ASP page.
helgeg