Setting InitialDirectory

G

Guest

Does anybody know how to set the InitialDirectory Property for Open or SaveFileDialog? Nothing I do seems to open either in the directory I specify. If I'm way off here does anybody know how to open these dialogs to display a specific directory

Here's the code I'm using for the InitialDirectory specification. I've also tried specifying this in the SaveFileDialog1 property window.

Dim SaveFileDialog1 As New SaveFileDialo
SaveFileDialog1.InitialDirectory = "c:\My Documents

Any help would be appreciated

Thanks
 
J

Jay B. Harlow [MVP - Outlook]

Chuck,
Which OS are you on?

Does "C:\My Documents" actually exist?

I normally use code similar to:

Dim dialog As New SaveFileDialog
dialog.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
dialog.RestoreDirectory = True
dialog.Filter = "My files(*.my)|*.my|All files (*.*)|*.*"
dialog.FilterIndex = 1
dialog.DefaultExt = "my"
If dialog.ShowDialog() = DialogResult.OK Then
Dim stream As Stream = dialog.OpenFile()
Serialize(stream, document)
stream.Close()
End If


Which will set the initial directory to the "My Documents" folder for the
current user independent of the OS version.

Hope this helps
Jay

Chuck said:
Does anybody know how to set the InitialDirectory Property for Open or
SaveFileDialog? Nothing I do seems to open either in the directory I
specify. If I'm way off here does anybody know how to open these dialogs to
display a specific directory?
Here's the code I'm using for the InitialDirectory specification. I've
also tried specifying this in the SaveFileDialog1 property window.
 
K

Kent Boogaart

I am a C# programmer so apologies if this is irrelevant: do you need to
escape the "\"? In C#, you would code it in one of these ways:

1) SaveFileDialog1.InitialDirectory = "c:\\My Documents";

2) SaveFileDialog1.InitialDirectory = @"c:\My Documents";

Not sure about VB.NET though . . .

Kent
 

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