In my C # .NET 2.0 application, I get access to network paths, and I would like to know the difference between paths that do not exist and paths that exist, but for which I do not have permission. I tried to do the following:
try
{
string[] contents = Directory.GetFileSystemEntries( path );
}
catch( Exception e )
{
if( e is DirectoryNotFoundException )
MessageBox.Show( "Path not found" );
else
MessageBox.Show( "Access denied" );
}
This works fine for local paths, but for network paths, the exception is always a System.IO.IOException, regardless of the cause of the error. In the "Exception message" field, another message is displayed depending on whether the path exists or not, so that the information is available at some point, but I cannot get to it. Is there a way to distinguish between "path not found" and "access denied" for network paths?
: , , - , henrik peSHIr, :
try
{
string[] contents = Directory.GetFileSystemEntries( path );
}
catch( IOException e )
{
uint error = (uint)Marshal.GetHRForException( e );
if( error == (uint)0x80070041 )
{
this.SuperProprietaryTechniqueForGettingAccessRights();
}
else
{
MessageBox.Show( "NO! BAD USER!" );
}
}
catch
{
}
Sam Hopkins