473,398 Members | 2,212 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,398 software developers and data experts.

contentType for text documents?

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
Nov 19 '05 #1
7 1460
How about just checking the file extension?

--
HTH,

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

"darrel" <no*****@hotmail.com> wrote in message
news:eq****************@tk2msftngp13.phx.gbl...
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

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

"darrel" <no*****@hotmail.com> wrote in message
news:Oo*************@TK2MSFTNGP12.phx.gbl...
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

Nov 19 '05 #4
> 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
Nov 19 '05 #5
> 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.

"darrel" <no*****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #6
> I didn't say there WAS any point to doing that! There IS no point to it.

Good to know! Thanks.

-Darrel
Nov 19 '05 #7
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)
"darrel" <no*****@hotmail.com> wrote in message
news:eq****************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #8

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

Similar topics

3
by: Webgour | last post by:
How do you reproduce this vbscript in C# <% Response.ContentType = "text/plain" response.write "This is text type" %>
8
by: Bryan Glennon | last post by:
I have an aspx page. If I set the Response.ContentType = "application/voicexml+xml" then when I load browse to the page it downloads the file and opens .Net Studio to allow me to edit it. It...
5
by: David Lozzi | last post by:
Hello, this is a repost of a previous post of mine from today. I need to export multiple documents (doc, xls, ppt, jpg) and crystal reports to a single PDF file. I know how to export a single...
3
by: ad | last post by:
I create a MemoryStream form a dataset: MemoryStream sm= new MemoryStream(); dsHealth.WriteXml(sm); I use Response.Write() to send this XML MemoryStream as file to client. What is the...
5
by: Carstonio | last post by:
I use ASP to display links to Word documents on an intranet. Is there a way in ASP to do text searches on the documents' contents? I want the results to have the link to the Word document plus two...
1
by: Roel | last post by:
Hi all, I'm using the FileUpload control for uploading MS Word and MS PowerPoint documents. To check if a user uploads a correct document, I check the contenttype...
1
by: rguarnieri | last post by:
Hi!, I'm using Visual Studio 6.0 and I'm trying to open an asp page like a .pdf file, I used Response.ContentType="application/pdf" in my asp page but it doesn't work This is an example: <%@...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
3
by: SteveB | last post by:
I have posted this question in the Visual Basic 2005 and Visual Basic .Net 2005 discussion groups, also. Hi. I am developing an application/web page with VB.Net that will populate a SQL...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.