user1370184
user1370184

Reputation: 41

OpenFileDialog - InitialDirectory open a remote directory

I have been trying to use the InitialDirectory on remote server without success. What I am trying to do is that: (comboBox1 has name of servers)

OpenFileDialog ofLogFile = new OpenFileDialog();
ofLogFile.Title = "Log for server: " + comboBox1.text;
OpenFileDialog.InitialDirectory = "\\\\" + comboBox1.text + "\\c$";
ofLogFile.RestoreDirectory = true;

and then there is an if check..

But it doesnt work. All i get is the local machine directoies. The thing is, when i put into InitialDirectory-

    OpenFileDialog.InitialDirectory = @"\\server_name\c$";

It works just fine. Another thing that i tried to put is:

OpenFileDialog.InitialDirectory = "\\\\" + ((System.Data.DataRowView)
(this.comboBox1.SelectedItem)).ToString + "\\c$";

It also doesnt work.

I am starting the program with the appropriate permissions so it shouldn't be an issue. any suggestions?

Upvotes: 3

Views: 2942

Answers (2)

Tergiver
Tergiver

Reputation: 14517

If

ofLogFile.InitialDirectory = @"\\server_name\c$";

Works, but

ofLogFile.InitialDirectory = @"\\" + comboBox1.Text + @"\c$";

Does not work, the answer seems obvious:

comboBox1.Text does not contain the correct string.

Make sure the combo box text does not contain easily missed characters like leading or trailing spaces.

Upvotes: 2

banging
banging

Reputation: 2560

Shouldn't it be:

ofLogFile.InitialDirectory = "\\\\" + comboBox1.text + "\\c$";

?

Upvotes: 3

Related Questions