Frage

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 ??

War es hilfreich?

Lösung

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);
}

Andere Tipps

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top