ahmedmalam

Hello/Salam Guys/Gals

I am currently working on a Real Online Estate Agency Project. I am facing a problem.

Suppose I got a file name through Input type file

D:\Wallpapers\Places\karachi.jpg

I want to just filename with its extension. How Can i remove the previous portion of the filename "karachi.jpg".

File path will be dynamic or user can select file from any folder or path.




Re: Visual C# Express Edition I need Help.

Markku Behm

Hi

You can use this:

new FileInfo("D:\Wallpapers\Places\karachi.jpg").Extension;

This return string ".jpg".

Yours
Markku





Re: Visual C# Express Edition I need Help.

jrboddie

try:

using System.IO;

string simpleFileName = Path.GetFileName(string path);

 

This should just return the filename with extension.





Re: Visual C# Express Edition I need Help.

ahmedilyas

in addition you can also do this:

string filePath = "D:\somefolder\somefile.jpg";

string fileNameOnly = filePath.SubString(filePath.LastIndexOf(@"\"));