How to get FileName from whole path using C# .Net

Vasanth
 
on Jul 19, 2012 05:42 AM
6842 Views

I am having the following path on the string Say "C:\\Test\\SubTest\\a.jpg".

I need to seperate the folder name and file name seperatly.

Thanks.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Results 1 - 5 of 6
Mudassar
 
on Jul 19, 2012 05:45 AM

There's built in method in the System.IO.Path class

string fileName = System.IO.Path.GetFileName("C:\\Test\\SubTest\\a.jpg");

 

Vasanth
 
on Jul 19, 2012 10:20 PM

By this i can get only the filename seperatly.

But i need the folder name with it.

Thanks.

Mudassar
 
on Jul 20, 2012 12:27 AM

There are 2 folders in that path which folder name you need?

Vasanth
 
on Jul 20, 2012 03:18 AM

I need to store the folder name in a list or string.

Mudassar
 
on Jul 20, 2012 04:52 AM
on Jul 20, 2012 04:53 AM

Can you be specific in what you want to do?

In your path there are 2 folders Test and SubTest? Which you want ?

Or give me an example what you need in the output string

Since this will save time and you will get answer quickly

Results 1 - 5 of 6