How to add file view button in Windows Form using C #

I want to select a file on my local hard drive when I click the browse button.

I do not know how to use the OpenFileDialog control. Can anybody help me?

+65
c # winforms
Feb 15 2018-11-11T00:
source share
3 answers

These links explain this with examples.

http://dotnetperls.com/openfiledialog

http://www.geekpedia.com/tutorial67_Using-OpenFileDialog-to-open-files.html

 private void button1_Click(object sender, EventArgs e) { int size = -1; DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { string file = openFileDialog1.FileName; try { string text = File.ReadAllText(file); size = text.Length; } catch (IOException) { } } Console.WriteLine(size); // <-- Shows file size in debugging mode. Console.WriteLine(result); // <-- For debugging use. } 
+84
Feb 15 '11 at 4:00
source share
 var FD = new System.Windows.Forms.OpenFileDialog(); if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileToOpen = FD.FileName; System.IO.FileInfo File = new System.IO.FileInfo(FD.FileName); //OR System.IO.StreamReader reader = new System.IO.StreamReader(fileToOpen); //etc } 
+34
Feb 15 2018-11-11T00:
source share
 OpenFileDialog fdlg = new OpenFileDialog(); fdlg.Title = "C# Corner Open File Dialog" ; fdlg.InitialDirectory = @"c:\" ; fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ; fdlg.FilterIndex = 2 ; fdlg.RestoreDirectory = true ; if(fdlg.ShowDialog() == DialogResult.OK) { textBox1.Text = fdlg.FileName ; } 

In this code, you can put your address in a text box.

+16
Jul 25 '14 at 7:57
source share



All Articles