[ACCEPTED]-How to present credentials in order to open file?-filesystems

Accepted answer
Score: 12

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

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

using (new Impersonator("myUsername", "myDomainname", "myPassword"))
  string fileText = File.ReadAllText("c:\test.txt");
Score: 6

I have used the Nuget package NuGet Gallery | Simple Impersonation Library 1.1.0 but there 3 are others; search on Impersonation for 2 the others.

Example usage using the interactive 1 login to work with file structures:

using (Impersonation.LogonUser("{domain}",
     var directory = @"\\MyCorpServer.net\alpha\cars";


James' answer below was before Nuget and before he would later have the most downloaded package on Nuget. Ironic eh?

Score: 0

You can impersonate a user who has the necessary 2 rights. There is an article on MSDN that describes how 1 to do this.

More Related questions