I am trying to find out if a file exists in a shared drive from a Windows machine in the local network. The drive can be easily mounted and accessed with my machine and it does not require credentials. I am using Visual Studio on Mac
I am using the following code in c# and exists is false:
FileInfo fileInfo = new FileInfo(@"\\servername\folder\file.pdf");
bool exists = fileInfo.Exists;
I think that the issue is that FileInfo does not actually access the shared drive and path in the argument, but checking for the following instead:
"/Users/me/Projects/CurrentProjectFolder/\\\\servername\\folder\\file.pdf"
The above path is the value of the FullPath and FullName property of the fileInfo object and I believe it does not find the file because it actually checks for this full path.
For example, trying to get the files for that directory throws a DirectoryNotFoundException.
Directory.GetFiles(@"\\servername\folder\");
Could not find a part of the path '/Users/me/Projects/CurrentProjectFolder/\\servername\folder\'.
I have been spending quite some time for a solution and there a high number of answers that follow the exact same operation I have pasted above - FileInfo with a UNC patch as argument.
Thanks