open file dailog control (win forms)

Posted by Kishore under C# on 3/7/2010 | Views : 1674 | Status : [Member] | Replies : 2
hi guys,

i created a form that contains one textbox and one button control, when i click the button a open file dialog box will be opened and the selected file name will be displayed in textbox. i know one logic ie

system.io.path.getfilename(openfiledialog1.filename);

but it displays the file extension also, i want only the file name plz help?




Responses

Posted by: Abhi2434 on: 3/7/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
You have to use

string filename = System.IO.Path.GetFileName(openfiledialog1.FileName);
filename = filename.Substring(0, filename.LastIndexOf('.'));

the filename will hold the name of the file without extension..

Cheers.

www.abhisheksur.com

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 3/26/2010 [Member] Bronze

Up
0
Down
Hii friend


Check following Article

http://www.geekpedia.com/tutorial67_Using-OpenFileDialog-to-open-files.html


Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response