views:

299

answers:

3

hello ,

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 path, I need to provide credentials lets say Admin and password 123.

Im using Asp.net, c# 3.5

Any Ideas

+2  A: 

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

remi bourgarel
I added to my web.config <identity impersonate="true" userName="domain\Admin" password="123" />Im having the following error Configuration ErrorDescription: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.Parser Error Message: Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Logon failure: unknown user name or bad password.
A: 

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.

Paul Ruane
A: 

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.

David Pfeffer
can u give me a link or an example how to do thatThanks in advanced