How to set a path for savefiledialog

1.8k views Asked by At

I want to set a path when saving. Here's my code. This code is supposed to set a path but it didn't work

SaveFileDialog1.ShowDialog()
SaveFileDialog1.InitialDirectory = "C:\Users\owner\Downloads"
3

There are 3 answers

0
Andrey Korneyev On BEST ANSWER

You have to set InitialDirectory before you're showing your dialog.

SaveFileDialog1.InitialDirectory = "C:\Users\owner\Downloads"
SaveFileDialog1.ShowDialog()
0
Adumuah Dowuona On

Declare path before showing dialog

string path="C:\Users\owner\Downloads";
SaveFileDialog1.InitialDirectory = path;
SaveFileDialog1.ShowDialog();
1
Alparslan ŞEN On
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.InitialDirectory = @"C:\"; //you should to set before showing dialog
        dialog.Title = "My Title";
        dialog.CheckFileExists = true;
        dialog.Filter = "Notepad (*.txt)|*.txt";
        dialog.ShowDialog();