Alex
Alex

Reputation: 4938

How To Verify Network Folder Access

Goal

To verify if a user has access to write / delete files on a specific network folder. For example:

\\MyCompany\Department\DocumentCenter\ is the directory where all the files are stored for the document center program. If a user has access to this folder, he is able to add / edit / delete files. If not, an error is caught by my try-catch.


Current Solution

I have attempted to solve this by setting up a try-catch right before the user deletes the file. If the user encounters an error, he will get a message saying that he does not have access... I find this rather trivial and would like a more concrete way of determining if the user has access to this folder.


How do I verify if a user has access to this specified folder?

Upvotes: 1

Views: 1171

Answers (1)

Alex
Alex

Reputation: 4938

When attempting to add / edit / delete a file on the given directory, as mentioned, I provide a try catch like so:

Private Sub DeleteFile(ByVal Path As String)
    Try
        'Example of Path: \\MyCompany\Department\DocumentCenter\File.PDF
        File.Delete(Path)
    Catch ex As Exception
        MsgBox("Cannot delete this file. Contact your system admnistrator to have access to this directory.")
    End Try
End Sub

Upvotes: 2

Related Questions