contentType for text documents?

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I'm creating a file upload tool, and want to allow only DOC, XLS, PDF, RTF
or TXT files. I am using this to check:

if (contentType = "application/msword") _
or (contentType = "application/rtf") _
or (contentType = "application/ms-excel") _
or (contentType = "application/pdf") _
or (contentType = "application/txt") then

However, I'm not sure if that's the proper way...namly the 'msword' vs.
'ms-excel' (the two examples I found online).

Does the above look correct?

-Darrel
 
How about just checking the file extension?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
How about just checking the file extension?

That's what I'm falling back on. Does changing the extension also change the
content-type? If so, then I guess it makes sense to just test for the file
extension.

I'm avoiding the 'hmm...my powerpoint file won't upload...Oh...I'll just
change the file extension...' issue.

-Darrel
 
Okay, let's talk about Content type. It's an HTTP entity, that is, it is
used by internet web applications when sending a stream of data. It tells an
Intenet HTTP client what kind of file it is. However, although the client in
this case is sending the file, by the time your code gets to it, it's just a
file stream again. So, how does your OS determine what kind of file a file
is? It uses the file extension. So, how should you tell what kind of file it
is? Check the extension.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Okay, let's talk about Content type. It's an HTTP entity, that is, it is
used by internet web applications when sending a stream of data. It tells an
Intenet HTTP client what kind of file it is. However, although the client in
this case is sending the file, by the time your code gets to it, it's just a
file stream again. So, how does your OS determine what kind of file a file
is? It uses the file extension. So, how should you tell what kind of file it
is? Check the extension.

Ah, so, what, exactly, is the point in grabbing the contentType if it simply
is based of the file extension?

Sounds like they are the same thing, at least when reading the file in.

-Darrel
 
Ah, so, what, exactly, is the point in grabbing the contentType if it
simply
is based of the file extension?

I didn't say there WAS any point to doing that! There IS no point to it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
I didn't say there WAS any point to doing that! There IS no point to it.

Good to know! Thanks.

-Darrel
 
when the browser uploads a file, it does not work hard to get a mime-type,
it usually sends, text, xml or binary (requires encoding). so you need to
check the file extension it supplies as it will be more accurate.

-- bruce (sqlwork.com)
 
Back
Top