I have a C# process that needs to read a file existing in a share directory on a remote server.
The below code results in "Share does not exist." being written to the console.
string fileName = "someFile.ars";
string fileLocation = @"\\computerName\share\";
if (Directory.Exists(fileLocation))
{
Console.WriteLine("Share exists.");
}
else
{
Console.WriteLine("Share does not exist.");
}
The process is run under an AD user account and the same account is granted Full Control permissions on the share directory. I can successfully map the share as a network drive on the machine the process resides on and can copy files to/from the directory. Any ideas on what I'm missing?
Use
File.Exists
rather thanDirectory.Exists
.Plus, you may want to be somewhat platform-agnostic and use the canonical
Path.Combine
as such: