Lukas Bystricky
Lukas Bystricky

Reputation: 1272

Setting default folder for openfile dialog

I have a OpenFileDialog and I am trying to set the default folder. Initially I had it set to Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\\new_folder1" and that worked well. However I changed it to Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\\new_folder2" and it still pops up in new_folder1. When I debug it, the dialog's InitialDirectory is new_folder2. I deleted new_folder1, but the dialog still looks for it when it starts up. There are now no references anywhere in my code to new_folder1.

Any ideas as to what might be happening?

Edit: Here is the code where I set up my initial OpenFileDialog:

 OpenFileDialog dlg = new OpenFileDialog();
 dlg.Filter = "XML files (*.xml)|*.xml";
 String pathDefault = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\\new_folder2";
 dlg.InitialDirectory = pathDefault;

Upvotes: 2

Views: 10896

Answers (1)

Adam Plocher
Adam Plocher

Reputation: 14233

You're using @"\\....". Either get rid of the @ or change the \\ to \.

Or, try:

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"new_folder2")

Upvotes: 1

Related Questions