开发者

Using DirectoryInfo with a UNC path

I'm trying to DirectoryInfo to verify whether a UNC path exists, however DirectoryInfo consistency fails over and says the folder doesn't exist, when I can confirm it does in Windows Explorer.

Example

var storagepath = new DirectoryInfo(@"\\123.123.123.123\c$\testfolder\test1开发者_运维技巧\");

if (storagepath.Exists)
{ }

Is there a way around this?


There are a few questions that need to be answered in regards to your program.

Is it running in the same context as the user that you're verifying with explorer? Is it possible you are, for example, running a console application as a restricted user but logged in as a higher privilege user, etc?

One of the reasons for Exists being false includes not having permission to access the resource.

You could try another method like EnumerateDirectories and see what the result is. The exceptions and results of EnumerateDirectories are a bit more descriptive than Exists.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜