C# file selection and network access?

989 views Asked by At

I'm creating a very simple application that will select files from local drive or from PC connected in a network. Application has a "checkbox" that can be checked True or False. Is it right to connect from Network location?? How can I create file browse button with it?

private void connect()
{
   try
   {
       if (checkbox1.Checked == false)
       {
          FilePath = @"C:\FILE";
       }
       else
       {
          FilePath = @"\\192.168.0.2\file\"; // That I want Is it work?
       }
       strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + FilePath + @"\;Extensions=csv,txt";
       Connect = new OdbcConnection(strConn);
       Connect.Open();
   }
   catch (Exception Ex)
   {
       MessageBox.Show(Ex.Message);
   }
}
1

There are 1 answers

4
Ludovic Feltz On BEST ANSWER

You want to open a file browser on the network ? Did you try OpenFileDialog ? It works on network path too, You can use it like this:

OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = FilePath;
openFileDialog1.ShowDialog();