Last post Nov 07, 2017 05:09 AM by Cathy Zou
Nov 06, 2017 06:18 AM|Binumon003|LINK
How to do check Authentication while save one xml file in network shared folder?
I need to save one xml file in network shared folder from my c# console application? if we need to pass user name and password how to do that?
Nov 07, 2017 05:09 AM|Cathy Zou|LINK
To access to the remote computer on a local network, you need to set up the credentials then access the network share.
You could use the credential class lives in the System.Net.namespace, by the name of "NetworkCredential".
When you have checked authentication and accessed into the network share folder, then you could save your xml file.
You could refer to the code as below:
NetworkCredential theNetworkCredential = new NetworkCredential(username, password, domain);
CredentialCache theNetcache = new CredentialCache();
theNetCache.Add(@"\\computer", theNetworkCredential, "Basic", theNetworkCredential);
//then do whatever, such as getting a list of folders:
string theFolders = System.IO.Directory.GetDirectories("@\\computer\share");
Make sure that the share has the appropriate user account added into the permissions, then try the code.