var di = new DirectoryInfo(Root);
var diList = di.GetDirectories();
上面的內容在訪問位於網絡上的文本路徑「Root」時崩潰。我只在用戶首次登錄到Windows 7時纔會發生(未在其他操作系統上測試過)。如果用戶使用Windows資源管理器導航到指定的路徑,則di能夠檢索目錄。var di = new DirectoryInfo(路徑)拋出異常,直到我使用Windows資源管理器第一次打開路徑
我知道做一個捕獲,並提示用戶點擊一個鏈接,打開Windows資源管理器和導航到路徑可以完成,但我不是一個解決辦法。我希望我的程序能夠建立到網絡路徑的連接,而不需要Windows資源管理器首先執行它。
例外:
System.IO.IOException: The network name cannot be found.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path,string originalUserPath,
String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler,
Boolean checkHost)
at System.IO.DirectoryInfo.InternalGetDirectories(String searchPattern,
SearchOption searchOption) at Controls.ValidationControl.LoadDBox(Object sender,
RoutedEventArgs e)
in c:\Controls\ValidationControl.xaml.cs:line 1010
預先感謝您的支持, 約翰
你能分享當它「崩潰」時發生的實際異常嗎? – Scottie
{System.IO.IOException:無法找到網絡名稱。 在System.IO .__ Error.WinIOError(的Int32的errorCode,字符串maybeFullPath) 在System.IO.FileSystemEnumerableIterator'1.CommonInit() 在System.IO.FileSystemEnumerableIterator'1..ctor(字符串路徑,串originalUserPath,字符串是searchPattern ,SearchOption searchOption,SearchResultHandler'1 resultHandler,Boolean checkHost)在System.IO.DirectoryInfo.InternalGetDirectories(String searchPattern,SearchOption searchOption)上的Controls.ValidationControl.LoadDBox(對象發件人,RoutedEventArgs e)位於c:\ Controls \ ValidationControl.xaml中。cs:1010行 – Cyphryx
注意:private const string Root = @「\\ networkPath」; – Cyphryx