Ketone Cops

January 31, 2008

FileUpload control and ContentType

Filed under: ASP.NET 2.0 — delroger @ 10:06 pm
Tags: , , ,
In one of my recent .NET 2.0 web apps, I’d created a page with a file upload facility. In the code-behind page, checking was done for the file extension, file size and content type. Everything seemed to work fine with it until one site user reported that they were unable to upload a Word document. I found out that even though the file extension was being reported correctly, the ContentType of the file was being reported as “application/octet-stream” rather than “application/msword”. Since I’d specifically excluded “application/octet-stream” from permission to be uploaded, the upload failed.

This had me puzzled for quite a while. Even though I could simply have disabled the check for ContentType and relied just on the file extension, I wanted the extra confirmation of file type in code.

I finally managed to re-create the problem the user had reported: I opened a Word document and then tried to upload it while it was still open. In this scenario, the Word document was reported as an “application/octet-stream”; the same thing happens with Excel files, and presumably other Office file types too. All I had to do was add code to tell the user to close their documents: problem solved.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: