0

Hi Guys,
I am trying to display a selected file name by user(using OpenFileDialog class and FileName property) as

if (dlgOpen.ShowDialog() == DialogResult.OK)
    {
     txtFileName.Text = dlgOpen.FileName;
    }

but the problem is this return all path info which I do not need! Can you please let me know How I can get rid of the path and just retrieve or display the file name only

Thanks for your time, in advanced.

Edited by Behseini: n/a

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Behseini
0

...or Path.GetFileName();

using System;
using System.IO;

namespace DW_398724
{
   class Program
   {
      static void Main(string[] args)
      {
         string strFilepath = "c:/documents and settings/user/directory/sub_director/text.txt";
         Console.Write(Path.GetFileName(strFilepath)); // prints text.txt
      }
   }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.