I've a problem with the way File.Exists()
(doesn't) work: when I use it, it claims that the file doesn't exist (from Immediate Window):
filePath "P:\\poolman\\LY21\\2015\\LY21_2015-03-25_03.xml" File.Exists(filePath) false
But if I copy/paste the file path to an explorer window url (removing the escaping \
) it opens the file.
So File.Exists()
claims that an existing file doesn't exist which bug me.
It's not about the length of the path (which is 43) and FileInfo
is not a better option as suggested here.
Here's the result of the FileInfo
check:
var f = new FileInfo(filePath); {P:\poolman\LY21\2015\LY21_2015-03-25_03.xml} base: {P:\poolman\LY21\2015\LY21_2015-03-25_03.xml} _name: "LY21_2015-03-25_03.xml" Directory: {P:\poolman\LY21\2015} DirectoryName: "P:\\poolman\\LY21\\2015" Exists: false IsReadOnly: true Length: '(var f = new FileInfo(filePath);).Length' threw an exception of type 'System.IO.FileNotFoundException' Name: "LY21_2015-03-25_03.xml"
How could I deal with it?
The major reason why your mapped network drive isn't appearing in network locations is User Account Control mostly forbids the mapped network drive from showing on the screen. Moreover, the File Explorer also causes problems for showing up the mapped network drive even if you're using the standard rights.
To use this command, follow the steps below. Click Start, Run, type cmd, and press Enter . At the MS-DOS prompt, type net share and press Enter . Each of the shares, the location of the resource, and any remarks for that share are displayed.
If you run a process (such as Visual Studio) elevated (as you claim in comments), it's not running as your current Windows user, but as Administrator.
Administrator does not have the drive mappings that your user has. So your Visual Studio cannot see the P:
drive at all, because that mapping is specific to your user.
See How to access network shares from an elevated process in Windows 7?: if this error is caused by your current user having the P:
drive mapped to a network drive, you can use the UNC path to the share instead: \\server\share\file.xml
, where P:
would be mapped to \\server\share\
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With