DriveInfo.GetDrives method problem.

  • Thread starter Thread starter Emil
  • Start date Start date
E

Emil

Hi,
I've written an application similiar to Total Commander but there is one
problem. To obtain all available drive letters I use DriveInfo.GetDrives()
method but it works only on my computer. If I try running this application
on other computers I get an IOException. What should I do ?

PS. Merry Christmas to everyone.
 
Place Try..catch block for the statement DriveInfo.GetDrives() and
catch the IO Exception Properly. Exception.Message would give you the
reason why it is failed. Sample code here

try
{
DriveInfo[] driveInfo = DriveInfo.GetDrives();

foreach (DriveInfo di in driveInfo)
{
Console.WriteLine(di.Name);
}
}
catch (IOException exp)
{
MessageBox.Show(exp.Message);
}

Compile the code in "AnyCPU" mode

Thanks
-Srinivas.
 
Uzytkownik "Duggi said:
Place Try..catch block for the statement DriveInfo.GetDrives() and
catch the IO Exception Properly. Exception.Message would give you the
reason why it is failed.

I did as you wrote and the message is: "Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.".

It's sounds silly to me. All I wanted is just to read the disk label but the
CLR behaves like it was a virus at least. And still don't know what to do :(
 
Emil said:
I did as you wrote and the message is: "Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.".

It's sounds silly to me. All I wanted is just to read the disk label but the
CLR behaves like it was a virus at least. And still don't know what to do :(

Remember that the c# executable must reside on a local drive when
running it.
Managed applications which are run from the network have several
security restrictions, e.g. they are not allowed to access the file system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top