Question

I have an Application running in a server, that takes a username and file path. The idea to check if the user can read the file (the target user is not the same user running the program).

So how to check read permissions for specific user ??

Was it helpful?

Solution

I can't take responsibility for this as I googled it and the answer was by James Newton-King found here- How to present credentials in order to open file?


You want to impersonate a user who does have the rights to access the file.

I recommend using a class like this - http://www.codeproject.com/KB/cs/zetaimpersonator.aspx. It hides all the nasty implementation of doing impersonation.

using (new Impersonator("myUsername", "myDomainname", "myPassword"))
{
  string fileText = File.ReadAllText("c:\test.txt");
  Console.WriteLine(fileText);
}

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top