OpenFileDialog.InitialDirectory not behaving

Lance James 371 Reputation points
2022-02-19T17:04:59.643+00:00

I can't get the expected behavior intended. The desired directory does not open. It opens to My Documents.

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = System.IO.Path.GetFullPath(@"\fs01\home\customerinventory\");
openFileDialog.FileName = "";
openFileDialog.ShowDialog();

Or

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = @"\fs01\home\customerinventory\";
openFileDialog.FileName = "";
openFileDialog.ShowDialog();

Regards,
Lance

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,339 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lance James 371 Reputation points
    2022-02-20T11:46:34.697+00:00

    Viorel1, your suspicions were correct.

    If I manually navigate to the directory via File Explorer prior to running the program, the OpenFileDialog behaves as I intended.

    Reviewing the other properties and methods of OpenFileDialog, nothing pops as being the solution. Reset and RestoreDirectory seemed like candidates but their description seems to indicate otherwise.

    If I use folderBrowserDialog1.SelectedPath, I at least get to the directory and can navigate from there.

    Best Regards,
    Lance


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.