Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get ALL the MIME types instead of wrinting a huge case statement?

I want to populate

Response.ContentType = "text/plain";

From somewhere in the server/web/dictionary ALL possible MIME types according to file extension:

public string GetMimeType(string extension)
{
    //This is what I am looking for.    
}

Also, I have to rename the file (at least if going to be downloaded, so I have to know in advance if it's going to be opened or not.

like image 812
Shimmy Weitzhandler Avatar asked Dec 05 '25 17:12

Shimmy Weitzhandler


2 Answers

Umm... why? You're not going to be returning content of every possible type, are you?

Here's a list of common types: http://www.webmaster-toolkit.com/mime-types.shtml. There is no list that would include "ALL" types simply because any application vendor can create a custom one and associate it with a custom extension.

like image 97
ChssPly76 Avatar answered Dec 08 '25 10:12

ChssPly76


You can store the mimetype when the file is uploaded ( FileUpload.PostedFile.ContentType ) and send that when the file is requested.

like image 30
Paul van Brenk Avatar answered Dec 08 '25 10:12

Paul van Brenk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!