我正在尝试访问网络中的文件,但它给了我找不到路径的错误。我应该怎么做才能在.net MVC 3中使用c#检查网络中是否存在文件
File.Exists("\\102.102.112.250\\some_pictures\\" + apicturename + ".jpg")
这是网络地址\\102.102.112.250\some_pictures
做了我的研究,但仍然找不到正确的答案..
我正在尝试访问网络中的文件,但它给了我找不到路径的错误。我应该怎么做才能在.net MVC 3中使用c#检查网络中是否存在文件
File.Exists("\\102.102.112.250\\some_pictures\\" + apicturename + ".jpg")
这是网络地址\\102.102.112.250\some_pictures
做了我的研究,但仍然找不到正确的答案..
您可能只需要\
在路径的开头转义:
File.Exists("\\\\102.102.112.250\\some_pictures\\" + apicturename + ".jpg")
或者,您可能会使用:
File.Exists(@"\\102.102.112.250\some_pictures\" + apicturename + ".jpg")
这更容易阅读,因为您不需要\
逐字转义字符串。
创建指向同一位置的网络共享,并使用共享而不是 ip 来检查文件是否存在。