Open file dialog

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Open file dialog

 
0
  #1
Jan 4th, 2009
Dear guys,

Can anyone help me out to open up a windows default dialog box in C# to browse folder and the folder path be displayed in the lab/edit box.

I am new at C#. Just created a simple form application and now looking to do the backend coding

Regards,
Ali
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,956
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 283
ddanbe's Avatar
ddanbe ddanbe is online now Online
Posting Virtuoso

Re: Open file dialog

 
0
  #2
Jan 4th, 2009
If you are using VS 2008 or VS 2005 just drop an OpenFileDialog from the toolbox on your form
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Open file dialog

 
0
  #3
Jan 4th, 2009
Originally Posted by ddanbe View Post
If you are using VS 2008 or VS 2005 just drop an OpenFileDialog from the toolbox on your form

Yes, I am using VS 2008 and i've drag and drop an openFileDialog but how can I initiate it. It simply shows below the Main form i've created with buttons on it.

Do I need to initiate behind any button click event?

thx
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Open file dialog

 
0
  #4
Jan 4th, 2009
Hello, gallian99.
This may help you: OpenFileDialog Class - that for case if you're not dropped it on your form.
and this: Opening Files Using the OpenFileDialog Component - if it is on your form.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,956
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 283
ddanbe's Avatar
ddanbe ddanbe is online now Online
Posting Virtuoso

Re: Open file dialog

 
0
  #5
Jan 4th, 2009
You essentially do something like this
  1. private void button1_Click(object sender, System.EventArgs e)
  2. {
  3. if(openFileDialog1.ShowDialog() == DialogResult.OK)
  4. {
  5. // The ShowDialog does just what it says
  6. //Do whatever you like to do when you clicked OK button in the dialog, see also hints by Antenka
  7. }
  8. }
Last edited by ddanbe; Jan 4th, 2009 at 3:01 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Open file dialog

 
0
  #6
Jan 4th, 2009
Thanks that helps...

Can you also show me how to return the selected folder path in a label once user selects/browses the folder and presses ok in folderBrowserDialog

thx

Originally Posted by ddanbe View Post
You essentially do something like this
  1. private void button1_Click(object sender, System.EventArgs e)
  2. {
  3. if(openFileDialog1.ShowDialog() == DialogResult.OK)
  4. {
  5. // The ShowDialog does just what it says
  6. //Do whatever you like to do when you clicked OK button in the dialog, see also hints by Antenka
  7. }
  8. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Open file dialog

 
0
  #7
Jan 4th, 2009
Have you checked what properties and how to use the dialogbox as per the helpfile? If we hand you all the code you dont learn how to find these things and will end up frustrated as you have to ask for everything and it takes longer.

If you look at the dialogbox in the helpfile, it has examples, it shows how to get the filename and stuff back, then the label component has properties of its own and you can see how to apply them..

Far more pride and joy is got by doing it yourself.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Open file dialog

 
0
  #8
Jan 4th, 2009
Totally agree to your message. I just figured it out. Thanks to all the forum members who replied. Just one more thing as of now, can I truncate the selectedPath to only the folder name that the users selects. folderName shows the complete path and i don't have much space in the designed label to cater to the long and lengthy paths.


private void button2_Click(object sender, EventArgs e)
{

DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
folderName = folderBrowserDialog1.SelectedPath;
}
lPath.Text = folderName;

}



Originally Posted by LizR View Post
Have you checked what properties and how to use the dialogbox as per the helpfile? If we hand you all the code you dont learn how to find these things and will end up frustrated as you have to ask for everything and it takes longer.

If you look at the dialogbox in the helpfile, it has examples, it shows how to get the filename and stuff back, then the label component has properties of its own and you can see how to apply them..

Far more pride and joy is got by doing it yourself.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Open file dialog

 
0
  #9
Jan 4th, 2009
Sure, you can, e.g. using method LastIndexOf() to find the last slash character in the returned string ... your folder name will be placed after the last slash.
Last edited by Antenka; Jan 4th, 2009 at 3:59 pm. Reason: Mistaken :(
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Open file dialog

 
1
  #10
Jan 4th, 2009
Or you could do it more simply with System.IO.Path.GetDirectoryName
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC