SIGN UP MEMBER LOGIN:    
ARTICLE

Browse or Open a File

Posted by Mahesh Chand Articles | Windows Forms C# December 15, 2000
This sample code show you how to use OpenFileDialog class to open or browse a file.
Reader Level:

The OpenFileDialog class is defined in Windows.Forms class. You need to add to reference to System.Windows.Form.dll library and call using System.Windows.Forms before using the class.

The OpenFileDialog class can be used to open a file similar to CFileDialog's Open method in VC++. This class is derived from FileDialog. OpenFile method of this class opens a file which can be read by a steam.

In this sample code, I have use OpenFileDialog class to browse a file.

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 ;
}

Title member let you set the title of the open dialog. Filter member let you set a filter for types of files to open.



FileName member gives you the name of the selected file.

Login to add your contents and source code to this article
share this article :
post comment
 

In that we should have done button, when we click on done button that should store in that location

Posted by mahendra kanumuri May 30, 2011

i need open a new html file, when i press the button(in new browser)...

Posted by karthick perumal Feb 08, 2011

hi..
 
   I have one browse button and one text box. In the browse_button click event, I would like to browse the files and place the path name into textbox. For this i'vw written code like this by using openfile dialog.

private void brwsbtn_Click(object sender, EventArgs e)
        {
            if (openFD.ShowDialog() == DialogResult.OK)
            {
                  textBox1.Text = openFD.FileName;
            }
            textBox1.Text="";
        }

So that  i am able to select files only. how can i select and place the folders path in textbox.

In my application the user should able to select either file or folder through a single browse button. please suggest me how to write code for this.
thank you

Posted by J R Sep 06, 2010

How to browse the multiple files and get the all file names at a time

Posted by Sachin Jul 29, 2010

want to make a GUI to process multiple file.the GUI will have "browse file" button to browse file from drive.help me with the source code as i am newbiee in C#.

Posted by sankarshan mridha Jul 04, 2010
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor