Question about PostedFile MIME type

Discussion in 'ASP .Net' started by ME via .NET 247, Mar 18, 2005.

  1. 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?
    ME via .NET 247, Mar 18, 2005
    1. Advertisements

  2. 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.


    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    What You Seek Is What You Get.
    Kevin Spencer, Mar 18, 2005
    1. Advertisements

  3. ME via .NET 247

    Bruce Barker Guest

    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 (
    Bruce Barker, Mar 18, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.