How to get extension of the file from an string eg: abc.pdf I want only pdf.
I try split option given below:

" Split(filep.tostring,“.”) " (Note: filep is the variable in which my files are stored.)

I got the answer but what I can do when file name is “abc.xyz.pdf”


Hi there @ImPratham45,
You should be able to use:

strExtension = Path.GetExtension("strYourFilePath")

Which should store the necessary information within the “strExtension” variable.

Thanks in advance,


Hi @ImPratham45,

This way you can take all the file extensions.



@balupad14 @Mr_JDavey Actually I have one folder which contains pdf,txt,xls,xlsx,csv and many more. So I want to fetch the extension of all files. I get all file extensions by using for each using “Split(filep.tostring,“.”)” but problem occurs when file name is " xyz.abc.pdf" then it gives “abc” not pdf


Because you splitting by “.” and you have 2 dots there.
Try balupad method, where you will always get file extension.


But I think @balupad14 method gives me only .xls & xlsx.files. What if there are several types of files with different extensions?


if you will use path.GetExtension(path) you will always get an extension of file…


@pllo2ptk Thank you!!