Question about PostedFile MIME type

M

ME via .NET 247

I have a question about how System.Web.HttpPostedFile manages mime types using property ContentType in Windows.

When I upload a known "text/plain" file with no extension the property doesnt recognizes the type, showing a blank string or some weird characters. But if I put an extension like .pdf ou .exe to that same file the ContentType shows "text/plain".

Is that result expected?
 
K

Kevin Spencer

MIME types are not relevant to posted files. Why? Because you're dealing
with the file system, not anything to do with the web. When the posted file
is uploaded, it is simply an array of bytes (characters). The file type is
identified in the same way that the file system identifies any file type -
by its extension. If the file has no extension, and the program doesn't tell
the OS what type of file it is (text or binary), the OS has no way of
knowing the file type.

Therefore, you either need to make sure the file has the correct extension,
or know the file type and tell the app what type of file to save it as.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
B

Bruce Barker

the client when it uploads the files set the content type, HttpPostedFile
just reports what the client gave it. so the value set depends on the
clients implementation of mime-mappings.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top