tags:

views:

1234

answers:

2

I am using the following method to browse for a file:

    OpenFileDialog.ShowDialog()
    PictureNameTextEdit.Text = OpenFileDialog.FileName

Is there a way get ONLY the file name?

The FileName method returns the entire path and file name.

i.e. I want Foo.txt instead of C:\SomeDirectory\Foo.txt

+9  A: 

Use Path.GetFileName(fullPath) to get just the filename part.

Jon Skeet
A: 

//Following code return file name only

string[] FileFullPath; string FileName; objOpenFileDialog.Title = "Select Center Logo"; objOpenFileDialog.ShowDialog();

FileFullPath = objOpenFileDialog.FileNames[0].ToString().Split('\'); FileName = FileFullPath[FileFullPath.Length - 1]; //return only File Name

//Use following code if u want save other folder , following code save file to CenterLogo folder which inside bin folder//

System.IO.File.Copy(OFD.FileName, Application.StartupPath + "/CenterLogo/" + FileName, true);