Find Topics

Wednesday, January 25, 2012

Open File Dialog In .Net Windows Form Applications with C#

0 comments

If you want to add Some files in windows application you have to use open file dialog this is very useful in windows form application when we want some input as a file like images , docs etc...

open-file-dialog-geekstrack

here is the code for open file dialog 
OpenFileDialog fDialog = new OpenFileDialog();
Open Dialog Box window Title
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 only
fDialog.Filter = "JPEG Files|*.jpeg|GIF Files|*.gif";
this is used to set initial directory which means when you open dialog box the path will be in c drive of computer.
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());
}

Do you like this article it Take 5 Second to Share with your Friends

Subscribe Email alerts to receive more Tech Updates to your Inbox!

Not Getting? Feel free to ask

Please Leave Comments your Comments are always Helpful. I will try to reply to your queries as soon as time allows.

Regards,
Nishant Srivastava

No Facebook Account! No worries you can add Comments Here!

Leave A Reply