Running Visual Studio as Administrator does not see mapped network drives [duplicate]
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?
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\
.