Scoping Issues

  • Thread starter MichaelEvans1000
  • Start date
M

MichaelEvans1000

Please someone tell me what i'm doing wrong here. I trying to access
the "files" variable, however i'm getting an "object not set to a
instance". I want to be able to move to the next record if this
"UnauthorizedAccessException" error occurs.

Dim files As ReadOnlyCollection(Of String)
Dim obj As New WinControl
Dim WS As New CollectionWS.CollectionBroker
Dim ds As New System.Data.DataSet
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow
Dim Name As String
Dim Drive As DriveInfo
Dim Dname As String

WS.Credentials = System.Net.CredentialCache.DefaultCredentials

ds = WS.GetCollectionTypes
dt = ds.Tables(0)

'Get Local drive information

For Each Drive In System.IO.DriveInfo.GetDrives

Dname = Drive.Name
For Each dr In dt.Rows
Try
Name = dr.Item(1)
files = My.Computer.FileSystem.GetFiles(Dname,
FileIO.SearchOption.SearchTopLevelOnly, "*." & Name)

files.GetEnumerator.MoveNext()
obj.GetFileProperties(files, Name)
Catch ex As IOException
Exit For
Catch ex As UnauthorizedAccessException
'I want to move to the next record and try to access it
files.GetEnumerator.MoveNext()

End Try
Next
Next
 
M

Marina Levit [MVP]

What it means, is that the exception was thrown on the GetFiles call while
you were trying to assign a value to 'files'. Because an exception was
thrown, 'files' never got a value. It is still null.

Yet, in your catch, you are trying to use files. Well, you can't, it never
got a value, GetFiles failed and the files were never retrieved.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

The exception is thrown when you try to get the list of files, as you
don't have access to the folder. As you don't get any list of files, you
can not move to the next file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top