473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Question about PostedFile MIME type

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?

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>UcNXN7/muky2x65KnkV4Gg==</Id>
Nov 19 '05 #1
2 1908
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.

"ME via .NET 247" <an*******@dotnet247.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
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?

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>UcNXN7/muky2x65KnkV4Gg==</Id>

Nov 19 '05 #2
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)

"ME via .NET 247" <an*******@dotnet247.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
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?

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>UcNXN7/muky2x65KnkV4Gg==</Id>

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Gene Ellis | last post by:
Something strange is happening, but I bet it is a quick fix. My favicon image is showing up in the URL bar, for a couple of seconds, but then it disappears and the default browser icon is...
0
by: clevariant | last post by:
Hello, I'm tasked with creating a WSDL file that is compatible with .NET's code gen' tool, wsdl.exe. I'm getting an error in the code output saying "Missing soap:body input binding", which...
2
by: CVerma | last post by:
I'm using an html input control (System.web.UI.HTMLControls.HTMLInputFile) to upload files such as msword, excel, jpg, and pdf. I have the encType property set in the form:...
2
by: vips | last post by:
I am using asp.net (VB) for uploading the files on my server I am using input type file (runat=server) my code is If ( FileProductImage.PostedFile.ContentLength > 0 ) Then strurl =...
0
by: Jim Heavey | last post by:
Hello, I am following along with an example of how to do uploads and download from your application. The download seems to wok just fine, but the upload does not. Each time I attempt to upload,...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
4
by: =?Utf-8?B?Y3NsZWltYmFjaA==?= | last post by:
I am having trouble with uploading a file to a website. I can not figure what I am doing wrong. I have a .asp file that you put a username and password in that is connected to a database. One of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.