ARTICLE

Browse or Open a File using VB.Net

Posted by Praveen Kumar Articles | Visual Basic 2010 November 16, 2004
This tutorial explain how to Browse or Open a File by using OpenFileDialog Class.
 
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. 

Private fdlg As OpenFileDialog = New OpenFileDialog()
Private fdlg.Title = "C# Corner Open File Dialog"
Private fdlg.InitialDirectory = "c:\"
Private fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
Private fdlg.FilterIndex = 2
Private fdlg.RestoreDirectory = True
If
fdlg.ShowDialog() = DialogResult.OK Then
textBox1.Text = fdlg.FileName
End If

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.

share this article :
post comment
 

This was very useful, but I think the boobsss.jpg file in your explorer seems much more interesting than cslogo.gif. Maybe you should move it to the 'unzipped' folder.

Posted by Ryan Seabolt May 18, 2012

the coding is good. How do we open the selected file.

Posted by vikram rajendran Apr 20, 2011

hai i am using visuval studio 2010 i am already create more then 5 forms unfortunately i close the first design form but save all the forms already open my project that time only solution explore contains 4 forms only the first form cannot see when i am opening the file that contains 3 files 1.form1.designer.vb 2.form1.resx 3.form1.vb open this file means that time only open the coding part only open i cannot see the already design the window how to open the form any methods are available or short cut methods or key are available pls help to see the design form thanks.. S.Sivaraj sprs.sps@gmail.com

Posted by SIVARAJ S Feb 22, 2011

How do you browse and open a file in a web site folder like you would using OpenFileDialog?

Posted by Dave Giord Dec 29, 2010

I am making a program that have to automatically open a program and then send it over smtp or upload it to FTP. Is there a way?

Posted by Stephan van Kampen Jun 02, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
MOST LIKED ARTICLE
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.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor