Handle the file extention using the Path class
How to get file extension and change it if it is obligatory
take a look http://dotnetuniver.blogspot.com/
How to get file extension and change it if it is obligatory
Join the conversation! Your thoughts help the community grow.
Join to leave a comment
Members earn 10 SHARP for a comment, 10 SHARP for a reaction, and 250 SHARP for every blog they publish.
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegisterMembers onlyeBook · C#Modern CSharp Mastery - Advanced Guide for Experienced DevelopersDownload nowWrite a blog post and earn +250 SHARP when it is approved.
Write a blog
Bechir BejaouiPosted Jul 18, 2008, 7:05 AM EDT
if you want to get the extension of a given file without having to use the String class functions for example you can use the GetExtension static method of the class path first you define a string that represents your file path string oPath = @"C:\myFile.txt"; then the GetExtention path will return a string that represent the file extention string extention = Path.GetExtension(oPath);. Of Corse, if you want to substitute the extention for exemple the *.doc by *.docx then use ChangeExtension instead of the GetExtension one. ChangeExtension is also a static method of the Path class . If you have any question about this please send me back. I send you a smal project accoring to this
Mike GoldTOP 100Posted Jul 18, 2008, 6:13 AM EDT
wasn't clear from this entry what to do. Is this what you meant to type? string theExtension = Path.GetExtension(thePath);