6.2.13

Get File Extension from C#


While working in C#, I came to know about finding the file extension and wish to share the same with my blog readers.....

///// Sample code to get the file extension.
Add the namespace using system.io;
        string filename = @"C:\Users\venkat\Documents\venkat.doc";

 string extension = Path.GetExtension(p);
 if (extension  == ".doc")
 {
      messagebox.show ( " It's a word document ");
 }
Note: Please check the case sensitiveness
Cheers,
Venkatesan Prabu .J
Director - Kaashiv InfoTech - www.kaashivinfotech.com

No comments:

Post a Comment