skip to Main Content

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

2

Answers


  1. 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");
    
    Login or Signup to reply.
  2. For getting file extension from uploaded file (IFormFile), Use:

    System.IO.Path.GetExtension(file.FileName)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search