1

I'm trying to access a remote server to read an XML file, but I must log in the server first using username/password. I wrote this C# code to do this, but I'm still getting an exception (invalid username or password)

  XmlDocument Document = new XmlDocument();
string filePath = @"\\ServerIPAddress\C$\Temp\fileName.xml";
Document.Load(filePath);

I think the tricky part is to pass the username and password to the server. Any ideas?

user1926689
  • 21
  • 1
  • 5
  • Is this a mapped drive on your network? – Tim Jun 27 '13 at 08:15
  • 1
    As for your edit: now it's a duplicate of [How to provide user name and password when connecting to a network share](http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share). Please show what you have tried, as this question is not unique. If you found anything that didn't work, do mention what you tried and what happened. – CodeCaster Jun 27 '13 at 08:16
  • Take a look at this question and answer: http://stackoverflow.com/q/3198793/745969 – Tim Jun 27 '13 at 08:17

1 Answers1

0

You may like to use NetworkCredential for this. Check this MSDN Example.


Edit:

You may check this MSDN Example to copy file(s) over a network. You may use / modify this to read file(s) over the network.

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
  • I tried this before, but does not work: HttpWebRequest request = (HttpWebRequest)WebRequest.Create("ServerIPAddress"); request.Credentials = new NetworkCredential("userName", "password", "WORKGROUP"); – user1926689 Jun 27 '13 at 11:54