1

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;
   // ...
Windgate
  • 365
  • 1
  • 4
  • 14
  • Does the user has access to the network folder? and can the users PC even see the folder from their machine (firewalls, same network, etc)? – Brad Jan 20 '21 at 15:09
  • Yes, as I said in the last paragraph (I move that paragraph over the code sample for better reading) – Windgate Jan 20 '21 at 15:11
  • [Related](https://stackoverflow.com/q/37915835/1997232). This behavior (open last working directory) occurs if path is wrong. You've somehow made a mistake in `@"\\pc_name\sub_folder_1\sub_folder_2"`. Maybe open that folder using `OpenFileDialog` and inspect using debugger which path is it? – Sinatr Jan 20 '21 at 15:27
  • 2
    OpenFileDialog has no problem with UNC paths, provided that path is accessible and the credentials allows it. Check the credentials needed to access the sub-path. Try to set full access to `Everyone` for testing. – Jimi Jan 20 '21 at 15:32
  • The credentials the application run does not have access to the network drive. If you had a domain you could impersonate easily otherwise there might be a similar impersonate for non domain accounts. Setting the access to everyone like @jimi state might also fix that. – Franck Jan 20 '21 at 15:40
  • It works now with no changes... Same code... Polktergeist? I tried again based on your comments and it works fine, thanks. Could any of you say that as an answer to the question? Or otherwhise I can answer my question, don't know what to do in this case – Windgate Jan 20 '21 at 16:04

1 Answers1

1

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

Windgate
  • 365
  • 1
  • 4
  • 14