Read file on a remote server
I have a file on a remote server and I want to read this file. lets say the files location is:
string filePath = @"\\192.168.101.15\c$\program files\xxx\test.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
This code is for sure throwing an error: Logon failure: unknown user name or bad password.
How can I pass my credentials??
if I go start/run and put this p开发者_如何学Cath, I need to provide credentials lets say Admin and password 123.
Im using Asp.net, c# 3.5
Any Ideas
You have to use impersonation, ie execute your code with a user who has acces to the shared folder instead of asp.net user :
http://msdn.microsoft.com/en-us/library/aa292118%28VS.71%29.aspx
You have two way : -with code -with configuration
Your application will need to run as a user that has access to the UNC path, or else impersonate a user with such permissions, for the file load operation.
You'd need to be pre-authenticated on the share before you can access the files. It isn't something you can do just by passing a UNC path.
You might consider executing a net use
command via the shell programatically. That's the only way I can find to do this.
精彩评论