I have built an application and a service that can stream files between each other, but it seems that my code, which supposed to read directories on flash drives and CDs, only works on flash drives.
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();
}
}
}
When I try to do the same to CDs, I get this error:
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
It seems I cannot do both using the same code, but I have no idea on how to do it.