我已經構建了一個應用程序和一個可以在彼此之間傳輸文件的服務,但是似乎我的代碼(應該讀取閃存驅動器和CD上的目錄)僅適用於閃存驅動器。如何打開一個目錄來流過它
foreach (RadTreeNode l_node in m_fileExplorer.SelectedNodes) {
string l_sSelectedPath = l_node.Name;
FileAttributes l_fileAttr = File.GetAttributes(l_sSelectedPath);
if (l_fileAttr == FileAttributes.Directory) {
foreach (string l_sFilename in Directory.GetFiles(l_sSelectedPath, "*.*", SearchOption.AllDirectories)) {
m_qUpload.Enqueue(
new UploadDescriptor {
BatchDescription = m_tbDescription.Text,
BatchTimestamp = l_now,
BatchId = l_sBatchId,
Username = m_frmLogin.Username,
TargetUsername = l_sTargetUsername,
Filename = l_sFilename
}
);
AddProgressRow(l_sFilename);
l_nFilesInBatch++;
ms_sem.Release();
}
}
}
當我試圖做同樣的光盤,我得到這個錯誤:
System.UnauthorizedAccessException: Access to the path 'D:\' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.Open(String path, FileMode mode, FileAccess access)
at ActivePath.FileUploader.Frontend.UploadForm.UploadEx(Object sender, DoWorkEventArgs e) in c:\code\Customers\FIBI\PWFileUploader\PWFileUploaderApplication\UploadForm.cs:line 697
似乎都使用相同的代碼,我不能這樣做,但我對如何做到這一點不知道。
任何一個可以幫助我嗎?請。 –
您正試圖打開一個名爲'D:\\'的文件。這將*總是*失敗並出現拒絕訪問錯誤。它是一個目錄,而不是文件。你的代碼如何進入這個泡菜是不可能猜到的。使用調試器。 –