tags:

views:

24

answers:

1

I'm trying to set up a page that will allow users to download files from a shared drive (where the file is actually sent via the page). So far this is what I have.

public partial class TestPage : System.Web.UI.Page
{
    protected DirectoryInfo dir;
    protected FileInfo[] files;

    protected void Page_Load(object sender, EventArgs e)
    {
        dir = new DirectoryInfo(Server.MapPath(@"\\sharedDrive\Public"));
        files = dir.GetFiles();
    }
}

The aspx page looks kind of like this:

<% Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name); %>
<ul>
<% foreach (System.IO.FileInfo f in files)
{
    Response.Write("<li>" + f.FullName + "</li>");
} %>
</ul>

When I remove the erroneous parts of the code, the page tells me that the Windows Identity I'm using is my user (which has access to the drive). I don't understand what the problem could be or what it's even complaining about.

+1  A: 

You should not have to call MapPath for a UNC file path. Server.MapPath() builds a full local path a file given a path relative to the root of your ASP.NET application.

For example:

Server.MapPath(@"MyRelativeDir\MyRelativePath.txt")

might return c:\myiisappdir\MyRelativeDir\MyRelativePath.txt

The code below is illegal since the remote path is not relative to the application root:

Server.MapPath(@"\\sharedDrive\Public")

So if your IIS application's identity and the share permissions are correct, I would think the following should work:

DirectoryInfo info = new DirectoryInfo(@"\\sharedDrive\Public");
mjmarsh
Great explanation. I'm pretty sure it's working properly now :)
Joe Philllips