以管理员身份运行Visual Studio看不到映射的网络驱动器
我对File.Exists()
(不)的工作方式有问题:当我使用它时,它声称该文件不存在(来自立即窗口):
filePath "P:\\poolman\\LY21\\2015\\LY21_2015-03-25_03.xml" File.Exists(filePath) false
但是,如果我将文件路径复制/粘贴到资源管理器窗口URL(删除转义\
), 则会打开该文件 。
所以File.Exists()
声称现有的文件不存在,这让我感到File.Exists()
。
这不是路径的长度 (43),而FileInfo
不是这里建议的更好的选择。
这是FileInfo
检查的结果:
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"
我怎么处理它?
如果您运行的进程(如Visual Studio)已升级(正如您在注释中声明的那样),则它不会以当前Windows用户身份运行,而是以管理员身份运行。
管理员没有您的用户拥有的驱动器映射。 因此,您的Visual Studio根本看不到P:
驱动器,因为该映射特定于您的用户。
请参阅如何从Windows 7中的提升进程访问网络共享? :如果此错误是由当前用户将P:
驱动器映射到网络驱动器引起的,则可以使用共享的UNC路径: \\server\share\file.xml
,其中P:
将映射到\\server\share\
。