即時通訊使用FileSystemWatcher對象從文件夾中檢索文件。FileSystemWatcher.Path網絡共享驅動器異常
代碼工作很好的本地機硬盤/文件夾,但是當我使用網絡路徑拋出異常。
出於某種原因的代碼,如果我開始在調試模式下服務不拋出異常。如果我通過installutil安裝它,那麼這個異常再次拋出。 也許是有一些權限問題,但我不知道是什麼...
public LevelOneValidatedWatcher(string strLevelOneFolder)
{
FileSystemWatcher objFSW = new FileSystemWatcher();
objFSW.Path = strLevelOneFolder; /// <<<<<<<<<<<< EXCEPTION THROWN HERE
objFSW.Filter = "*.zip";
objFSW.Created += new FileSystemEventHandler(myWatcher_Created);
objFSW.Renamed += new RenamedEventHandler(mydWatcher_Renamed);
objFSW.EnableRaisingEvents = true;
}
System.ArgumentException was unhandled
Message=The directory name T:\INFORMATION TECHNOLOGY\bu is invalid.
Source=System
StackTrace:
at System.IO.FileSystemWatcher.set_Path(String value)
at MA.BatchTool.ServerLibrary.LevelOneValidatedWatcher..ctor(String strLevelOneFolder) in D:\Dev\Projects\MailAssurety1.1\Development\SourceCode\MA_1.1\WebServerSide\WebServerLibraries\LevelOneValidatedWatacher.cs:line 23
at MA.BatchTool.ServerLibrary.ServerJobProcessor.StartFileWatcher(Object strPath) in D:\Dev\Projects\MailAssurety1.1\Development\SourceCode\MA_1.1\WebServerSide\WebServerLibraries\ServerJobProcessor.cs:line 32
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
根據異常消息
可能進一步閱讀,路徑不存在..請確保您使用了正確的路徑。 –
嗨,路徑存在。它是一個共享驅動器。當我以調試模式啓動Visual Studio時,程序可以訪問路徑。在將服務安裝爲Windows服務之後,發生異常。 –
檢查[這裏](http://stackoverflow.com/questions/3622089/windows-service-cant-access-network-share)和[這裏](http://stackoverflow.com/questions/16946312/how-come -my-windows-service-can-access-a-folder-with-files-in-them)這些可能會幫助你。 –