UNC share directory does not exist

I have a C # process that needs to read a file that exists in a shared folder on a remote server.

In the code below, the result is "Share does not exist." recorded on 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 starts under the AD user account, and full access permissions in the shared directory are granted to the same account. I can successfully map the share as a network drive on the machine where the process is located, and can copy files to / from the directory. Any ideas on what I am missing?

+4
source share
1 answer

Use File.Exists , not Directory.Exists .

In addition, you may want to be platform incompatible and use the canonical Path.Combine as such:

 string fileName = "someFile.ars"; string fileServer = @"\\computerName"; string fileLocation = @"share"; if (File.Exists(Path.Combine(fileServer, fileLocation, fileName))) { Console.WriteLine("Share exists."); } else { Console.WriteLine("Share does not exist."); } 
+2
source

Source: https://habr.com/ru/post/1415463/


All Articles