Anjeneya Murthy
asked on
Issue in accesing the drive using Directory.GetFiles in C#
HI,
I am writing a program to find all the files with the specified filter. The program works fine if i give path to some folder, but throws an exception if i pass the drive letter as parameter. Can you please help me resolve this problem?
I am getting error UnauthorizedAccessExceptio n: Access to the path 'E:\System Volume Information' is denied.
I am writing a program to find all the files with the specified filter. The program works fine if i give path to some folder, but throws an exception if i pass the drive letter as parameter. Can you please help me resolve this problem?
I am getting error UnauthorizedAccessExceptio
string[] FileNames = Directory.GetFiles("E:\\","*.chm", SearchOption.AllDirectories);
foreach (string FullPath in FileNames)
{
FileInfo file = new FileInfo(FullPath);
string Path = file.DirectoryName;
string FileName = file.Name;
checkedListBox1.Items.Add(FileName);
}
ASKER
i did use try and catch to avoid the exception. but my criteria will not be solved. i want to gain access to the drive so that i want to search all the files and folders in that drive.
i want to somehow get access. i have admin privilages in my system, but still unable to do this :(
i want to somehow get access. i have admin privilages in my system, but still unable to do this :(
Do not know why accessing this folder ;-)
But here is what you are looking for:
http://support.microsoft.com/kb/309531
But here is what you are looking for:
http://support.microsoft.com/kb/309531
this will solve "System Volume Information" problem
string[] FileNames = Directory.GetFiles("E:\\","*.chm", SearchOption.AllDirectories);
foreach (string FullPath in FileNames)
{
FileInfo file = new FileInfo(FullPath);
string Path = file.DirectoryName;
string FileName = file.Name;
if(FileName == "System Volume Information") //Except System Volume Information folder
continue;
checkedListBox1.Items.Add(FileName);
}
this don't fix the problem..
exception will throw in 1 line..
(not if you change access to directory but it isn't good idea [http://support.microsoft.com/kb/309531])
exception will throw in 1 line..
(not if you change access to directory but it isn't good idea [http://support.microsoft.com/kb/309531])
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot. works fine.
Solution:
except "System Volume Information" from your code.
Or, to avide each and every inaccessable file: you have to you use try catch block as follows:
Open in new window