Common Dialog in C# (.NET)
CommonDialog was widely used to select the files in Visual Basic 6.0. .Net provides a OpenFileDialog component, which can be used for the same.
Let us have a small Windows form where the file to process is to be selected. The form contains a CommandButton to invoke the Open File dialog box and a TextBox to display the selected file.
To use the OpenFileDialog, insert the component from Toolbox to the form
When it is droped to a form, the OpenFileDialog component appears in the tray at the bottom of the Windows Forms Designer.
Now write the following code in the Button’s Click event to display the Open file dialog box
private void buttonSelectXL_Click(object sender, EventArgs e)
{
openXLFile.Filter = "Microsoft Excel Workbooks (*.xls)*.xls";
if (openXLFile.ShowDialog() == DialogResult.OK )
{
String sFileName = openXLFile.FileName;
txtExcelFile.Text = sFileName;
}
else
{
MessageBox.Show("Please select a file");
}
}
The above code filers only Excel files in the Open Dialog Box
The selected file will be displayed in the Textbox
See also OpenFileDialog in Visual Basic .Net
For CommonDialog implementation in VB6.0 refer http://vbadud.blogspot.com/2007/06/visual-basic-common-dialog.html
1 comments:
really good .
your blog is one of bests ;) .
thx.
Post a Comment