Home > Mobile >  How to Get the File Extension from IFromFile MicorsoftAspNetCore
How to Get the File Extension from IFromFile MicorsoftAspNetCore

Time:08-20

I'm trying to get the simple file extension for example "XLSX","pdf" and so on instead of the whole raw Content-type when I use IFromFile.ContenType gives me the raw content-type header on the uploaded file, any help is really appreciated

CodePudding user response:

For getting file extension from uploaded file (IFormFile), Use:

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

CodePudding user response:

If you are looking for the extension type, Use

var extension = Path.GetExtension(Server.MapPath("file.txt"));

For the Mime type

var mimeType  = MimeMapping.GetMimeMapping("file.txt");
  • Related