Setting FolderBrowserDialog.RootFolder yeilds error

J

Jerry West

I'm trying to set the .RootFolder property of the FolderBrowserDialog
object. Each time I try I get an error stating:

"Object reference not set to an instance of an object."

I have not opened the VB toolbox and placed a FolderBrowserDialog onto a
Form. Instead, I have simply declared a var as FolderBrowserDialog within a
module and attempted to use it. Is this the reason why I receive this error?

My goal was to simply create a wrapper for the FolderBrowserDialog in a
module and call that for any folder browsing needs.

JW
 
G

Guest

Are you doing this as follows?

Dim fbd As FolderBrowserDialog
fbd = New FolderBrowserDialog
fbd.RootFolder = Environment.SpecialFolder.Favorites
fbd.ShowDialog()

This works fine...
 
J

Jerry West

Yes, that is exactly what I am doing. My code is as follows:

With fld

.RootFolder = Environment.SpecialFolder.System

If (.ShowDialog = DialogResult.OK) Then

Do Something

End If

End With

As soon as the code path reaches...

..RootFolder = Environment.SpecialFolder.System

....I get the error indicated. Did you first place a FolderBrowserObject onto
a Form?

JW
 
G

Guest

Jerry,

No, I did not drag the FileBrowserDialog onto the form from the toolbox.
You are sure you have a statement in your code

fld = new FileBrowserDialog

just before your with clause?
 

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