C# file exists on network drive
-
In a C# 2008 desktop application, the application is having a problem determining if a folder exists on a network drive. I am using code that looks like the following:
using System.IO
if (!File.Exists(myfile))
Console.WriteLine("The file does not exists.");The value for the directory comes from a column in the database that looks like the following: //servername/mdain/myfile.xls". Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?
-
In a C# 2008 desktop application, the application is having a problem determining if a folder exists on a network drive. I am using code that looks like the following:
using System.IO
if (!File.Exists(myfile))
Console.WriteLine("The file does not exists.");The value for the directory comes from a column in the database that looks like the following: //servername/mdain/myfile.xls". Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?
The first thing I see is that your sample path you provided is wrong. You are using the wrong slash in the path, it should be "\\servername\mdain\myfile.xls". The second thing I would check is if the computer you are running the application on has permissions to access the network drive, since that would return false regardless of the file existing.
-
The first thing I see is that your sample path you provided is wrong. You are using the wrong slash in the path, it should be "\\servername\mdain\myfile.xls". The second thing I would check is if the computer you are running the application on has permissions to access the network drive, since that would return false regardless of the file existing.
-
In a C# 2008 desktop application, the application is having a problem determining if a folder exists on a network drive. I am using code that looks like the following:
using System.IO
if (!File.Exists(myfile))
Console.WriteLine("The file does not exists.");The value for the directory comes from a column in the database that looks like the following: //servername/mdain/myfile.xls". Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?
-
Forward slashes are fine in path names; Windows correctly interprets them.
Use the best guess
-
-
Eddy Vluggen wrote:
Most apps do not.
Well, you would not expect Microsoft's apps to do things properly, would you?
Use the best guess
Richard MacCutchan wrote:
Well, you would not expect Microsoft's apps to do things properly, would you?
If I wouldn't, I'd be recommending to use GNU/C, OpenOffice, MySql and black magic. Still I recommend to pay up for Microsofts' apps :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
I'm not sure how easy that would be but perhaps the
DirectoryInfo
[^] orFileInfo
[^] classes would help.Use the best guess
Thanks! this works!