I'm trying to create a Folder on a Win Server 2016 (on VM Ware) using C#. Below are my lines of code:
NetworkCredential theNetworkCredential = new NetworkCredential("username", "password");
CredentialCache theNetcache = new CredentialCache();
theNetcache.Add(new Uri(@"\\WIN-FM8PGNEC4OF\"), "Basic", theNetworkCredential);
string subdir = @"\\WIN-FM8PGNEC4OF\Archives\BN\" + entity + "\\" + folder;
if (!Directory.Exists(subdir))
{
try
{
Directory.CreateDirectory(subdir);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
I have granted full permission (read/write) to Everyone to the main folder called Archives, which my application uses for creating directories. I've also disabled anti-virus, disabled firewall. But the code keeps giving me exception of incorrect username or password. I've pinged the server using its name (WIN-FM8PGNEC4OF) and i get a positive response. What is funny though is, when I try to access the shared folder via run (Win + R), after prompt for username and password, I gain access via explorer, AS WELL AS THE APPLICATION STOPPED THROWING EXCEPTION (meaning the application creates the directory successfully). Please help me out from my misery.