Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi, I am using openFileDialog in c#. I am trying to take the path of the file I have selected from the openFileDialog.

Can someone point me to how this is done pleaseeee.

Cheers

Dan
Posted

C#
string path = System.IO.Path.GetDirectoryName(filename);
 
Share this answer
 
v2
Comments
fjdiewornncalwe 7-Jul-11 12:36pm    
of Course.
DanHodgson88 7-Jul-11 12:50pm    
cheers thats the one :) thanks for the help
Sergey Alexandrovich Kryukov 7-Jul-11 14:12pm    
Of course, a 5.
--SA
Do you mean
OpenFileDialog openFileDialog1 = new OpenFileDialog();

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    string p = openFileDialog1.FileName;
}
 
Share this answer
 
Comments
#realJSOP 7-Jul-11 12:34pm    
No. He wants to find the path of the selected file (you showed him how to get the selected file, which he already appears to know how to do).
fjdiewornncalwe 7-Jul-11 12:36pm    
Agreed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900