Windgate
Windgate

Reputation: 428

Set a network shared folder as InitialDirectory in an OpenFileDialog form

I'm trying to set a shared network folder as initial directory in an OpenFileDialog form. It is a internal-use-only app for my work, so it is safe to do that and it will save us a lot of time.

The code I'm trying is this, I can set any local folder ("C:/...") with no problem, but when I try to set the path of our network shared folder it has no effect and the form opens the last working directory.

All machines works with Windows 10 Enterprise, are in the same network, the path I'm using is writed correctly, the machine with the shared folder is power on and I have normal access from file explorer using that path with no problem.

// The OpenFileDialog control is named ofdFile in my .Designer
this.ofdFile.Title = "File " + formato.nombre;
this.ofdFile.Filter = "CSV Files | *.csv";
this.ofdFile.FileName = string.Empty;
this.ofdFile.InitialDirectory = 
    @"\\pc_name\sub_folder_1\sub_folder_2"; 
    // Also tried with the local IP, double '/', no @, and all kind of stuff...

if (ofdFile.ShowDialog() != DialogResult.Cancel)
   string myFilePath = this.ofdFile.FileName;
   // ...

Upvotes: 1

Views: 995

Answers (1)

Windgate
Windgate

Reputation: 428

The code above was correct and it is working now. Don't know why it didn't work on the first tests.

Upvotes: 1

Related Questions