locked
Handling File I.O. Access Denied in Vb.Net

    Question

  • Hi,

    I am getting into some difficulty with a path iterator.

    I am looping through directories and know that there are some files / directories that my AD account does not have access to.

    In this instance I want to skip over the file I don't have access to and carry on with the loop.

    Any Ideas?

    Here is the code

    Dim path As String="C:\Reports\"

    Try

    If Directory.Exists(path) Then

    For Each name As String In Directory.GetDirectories(path)'Throwing exception here as ntfs does not allow me access to particular dir

    children.Add(name)

    Next name

    End If

    Catch ex As Exception

    'I want to jump back into the loop and carry on on the next directory if I don't have access

    End Try

    Wednesday, February 11, 2009 9:26 AM

Answers

  • Arjun,Jie,

    Its ok - I managed to fix with a standard try catch block
    If exception thrown I ignore by checking if it's an unauthorisedaccess type



    Thanks anyway
    Thursday, February 12, 2009 12:00 PM

All replies

  • Are you talking about file access denied or directory access denied, Are you getting error in GetDirectories?

    Sorry but could not figure out
    "In this instance I want to skip over the file I don't have access to and carry on with the loop"
    Arjun Paudel
    Wednesday, February 11, 2009 6:17 PM
  • Hi,

    If calling Directory.GetDirectories(path) throws an exception, that means you're not getting any of the sub-directory names at all.

    So it will be meaningless to "jump back into the loop" because the loop never starts.

    Could you provide more information on the exception like its message and call stack so we can get a better idea what's going on?

    Thanks,

    Jie


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, February 12, 2009 11:34 AM
  • Arjun,Jie,

    Its ok - I managed to fix with a standard try catch block
    If exception thrown I ignore by checking if it's an unauthorisedaccess type



    Thanks anyway
    Thursday, February 12, 2009 12:00 PM