By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,061 Members | 1,539 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,061 IT Pros & Developers. It's quick & easy.

Scoping Issues

P: n/a
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

Nov 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

<Mi**************@gmail.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.com...
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

Nov 1 '06 #2

P: n/a
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.

Mi**************@gmail.com wrote:
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
Nov 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.