Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The easiest way is to just do it (i.e. try to read a file, for example). As Jared mentioned, there is no way to make sure that you will be able to read in the future (network failure, change of permissions, etc).</p> <p>As far as code goes, you could use the <a href="http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx" rel="nofollow noreferrer">DirectoryInfo</a> class for some attempts at an answer:</p> <pre><code> string remotePath = @"\\server\share$"; bool haveAccess = false; DirectoryInfo di = new DirectoryInfo(remotePath); if (di.Exists) { try { // you could also call GetDirectories or GetFiles // to test them individually // this will throw an exception if you don't have // rights to the directory, though var acl = di.GetAccessControl(); haveAccess = true; } catch (UnauthorizedAccessException uae) { if (uae.Message.Contains("read-only")) { // seems like it is just read-only haveAccess = true; } // no access, sorry // do something else... } } </code></pre> <p>There are many shortcomings in the above code (such as the hard-coded "read-only" test), but it is just an example used to illustrate what you could do. DirectoryInfo has a few other helper methods that you can use to list the files in the folder. If you don't have access, the methods will throw an <code>UnauthorizedAccessException</code> exception which you can use to test why the access failed. Check out the info on <a href="http://msdn.microsoft.com/en-us/library/t1h6d4k4.aspx" rel="nofollow noreferrer">GetAccessControl</a> for further details on the exceptions it throws.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload