How to get file type in file upload control?

I am using a file upload control. I got the file name for CreateDataBase.docx . Now i want fileType for docx

I have CreateDataBase.docx . I just need this file type, or I want to remove CreateDataBase

I have many files for xml, pdf, docx, etc. .So I want the file type or the following dot characters (.)

+4
source share
2 answers

you can just use

 System.IO.Path.GetExtension(FileUpload1.FileName) 

or you can just do

  string[] segments= FileUpload1.FileName.Split("."); string fileExt = segments[segments.Length-1] 
+6
source

try the following

  String FileExtension =System.IO.Path.GetExtension(FileUpload1.FileName); 
+1
source

All Articles