BlackPanic
BlackPanic

Reputation: 35

Change Path of OpenFileDialog

At the moment I am using this here in my WPF App which works as it should.

private void buttonPresentations_Click(object sender, EventArgs e)
        {
            openFileDialogPresentations.ShowDialog();
        }

It remembers the last path I was in but I want to change it to a set path now. I have 3 Radiobuttons and each Radiobutton should lead to a different path so I thought about doing it with a variable I give to the openFileDialog but I am not sure on how to go with that. Has anyone done this and can give me a lead on it ?

Upvotes: 1

Views: 85

Answers (3)

Dilip
Dilip

Reputation: 305

You can do it by using InitialDirectory property. You can set three different paths for radio buttons

  private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.InitialDirectory=@"D:\MyDir";
            dialog.ShowDialog();
        }

Upvotes: 0

Adil
Adil

Reputation: 148180

You can set IntitialDirectory to the folder you want in code where you show the dialog.

private void buttonPresentations_Click(object sender, EventArgs e)
{
    openFileDialogPresentations.IntitialDirectory = youFolderPath;
    openFileDialogPresentations.ShowDialog();
}

Upvotes: 3

CompuChip
CompuChip

Reputation: 9232

The standard file dialogs have an InitialDirectory property that determines in which folder the dialog opens.

private void buttonPresentations_Click(object sender, EventArgs e)
{
    openFileDialogPresentations.InitialDirectory = @"X:\Data\Presentations";
    openFileDialogPresentations.ShowDialog();
}

Upvotes: 0

Related Questions