In this example i m creating a Open file dialog box to browse and select a file to open in .NET windows applications using C# and winforms
Start a new Windows Application project and drag a button, double click on the button to generate it's click event
Now create a new openFileDialog
OpenFileDialog fDialog = new OpenFileDialog();
To set the title of window
fDialog.Title = "Open Image Files";
To apply filter, which only allows the files with the name or extension specified to be selected. in this example i m only using jpeg and GIF files
fDialog.Filter = "JPEG Files|*.jpeg|GIF Files|*.gif";
To set the Initial Directory property ,means which directory to show when the open file dialog windows opens
fDialog.InitialDirectory = @"C:\";
if the user has clicked the OK button after choosing a file,To display a MessageBox with the path of the file:
if(fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(fDialog.FileName.ToString());
}
If you want to select multiple files ,set the Multiselect property to true and to return the name of the files use fDialog.FileNames instead of fDialog.FileName. This will return a string array with the name of the files.
Other properties which we can use are :
fDialog.AddExtension = true;
if a user types the name of a file or path that does not exist we can give him an warning:
fDialog.CheckFileExists = true;
fDialog.CheckPathExists = true;
![]() |
||
|
|
![]() |
|
Mixx it!
|
add to del.icio.us saved by 0 users |











1 comments:
Thank you for nice post...you exaplained in easy way
Post a Comment