views:

119

answers:

0

We want to list files residing in a network share directory from the MOSS 2007 website web part. To do so i have impersonate the logged in user while accessing the network share directory using following code

IPrincipal p = System.Web.HttpContext.Current.User;
WindowsIdentity id = (WindowsIdentity)p.Identity;

// impersonate temporarily
WindowsImpersonationContext wic = id.Impersonate();
try
{
    // do some work while impersonating the client
    System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo( path );
     // get subdirectories of the current directory
     System.IO.DirectoryInfo[] SubDirectories = directory.GetDirectories();
}
finally
{
      //restore our old security context
     wic.Undo();
}

Above code does not impersonate as it is supposed to do, it still throws following exception: "Access to the path '[networksharepath]' is denied.

P.S: The logged in user does have full read privileges on network share.

Can any body tell me what is wrong with above code please ?