Software Code
    New Code     Most Interesting     Don't Miss     Our picks  
C# - section

View Article
OpenFileDialog example
Open File Dialog example
Use this code to enable the application to browse for a file using the "Open File Dialog" window.
public void BrowseForfile()
//Make an instance of the OpenFileDialog class
OpenFileDialog fileDialog = new OpenFileDialog();
//Set the initial directory
fileDialog.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); ;
//Configure the filter to browser HTML, TXT and ALL files
fileDialog.Filter = "Html Files (*.html)|*.html|Txt Files (*.txt)|*.txt|All Files (*.*)|*.*";
//Select the start filter = ALL Files
fileDialog.FilterIndex = 2;
//Tell if the folder should be restored
fileDialog.RestoreDirectory = false;

//Show the open file dialog
if (fileDialog.ShowDialog() == DialogResult.OK)
string resultFileName = fileDialog.FileName;
//Use resultFileName to further open the file
Date: 2007-12-13    Written by: Admin A
     See all articles in this section
Copyright © 2007-2009 SoftwareRiviera.com. All rights reserved.  | Terms of use | Disclaimer | Privacy Policy |