UnauthorizedAccessException vs IOException
.net-3.5, c#
Solution
My question is why for some shares i get the network path was not found and others the access denied? what is the different?
If the path is found quickly, but you don't have permission, you'll receive an `UnauthorizedAccessException` very quickly.
However, if the system is trying to discover whether the network share is even valid, this can take a while. It will need to do quite a bit of network access before it can determine that the network path isn't valid at all, and this can take time.
and how can i avoid the second exception which takes time.
The only real way to do this is not to access shares which do not exist. This isn't always practical - if you need to determine at runtime whether they exist, you'll just need to design around the fact that this may be slow.
There are many ways to improve this, however - if you're checking against multiple shares, you could do these checks in parallel. Given that this is really IO bound, threading could make a huge difference in overall responsiveness of your application as you can check all of the shares at the same time, instead of sequentially.
Problem
I'm listing some folders from Nas share, get folder properties and list sub folders. for folders where i have no access rights i get two different exceptions - `System.UnauthorizedAccessException`: Access to the path 'Z:\info' is denied. - `System.IO.IOException`: The network path was not found. The second one takes long time to be catch which slows down the application My question is why for some shares i get the network path was not found and others the access denied? what is the different? and how can i avoid the second exception which takes time.