how get only filename from the filepath in c#?

Posted by Unknown

To get the only file name from the file path

//write a method for getting a only file name //for reusabilty
public string getFilenameFromPath(string fileapth)
{

  int lastindex =fileapth.LastIndexOf('\\') + 1;
  string filename = fileapth.Substring(lastindex);
return filename;
}

you can use like this
direct Path
string filenae=getFilenameFromPath(" c:\\div\\smaple.png");

from fileuplaod
string filename=getFilenameFromPath( uploadFile.FileName);\\file system path i.e c:\\div\\smaple.png
Labels:

Post a Comment

 
test