Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2007, 02:17 AM
Registered User
 
Join Date: Sep 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sauravnimesh
Default restricting users to upload rtf or pdf files only

hi All,

i m in urgent need of some way to restricting users to upload the files other than of "rtf" or "Pdf"

the code i m using is below


string strUploadType = ctrBrowse.PostedFile.ContentType;
string strUploadedFilePath = ctrBrowse.PostedFile.FileName;
string strEjoinPathName = Server.MapPath("..//Uploads//");

strUploadType = ctrBrowse.PostedFile.ContentType;
strUploadedFilePath = ctrBrowse.PostedFile.FileName; intResumeSize = ctrBrowse.PostedFile.ContentLength;

if ((strUploadType != "application/msword" && strUploadType != "application/pdf") || intResumeSize > 500000)


it is working fine for normal case
but the problem is if i rename any image or exe file as .doc, it is taking it as "application/msword" based on extention of file.

can anybody suggest me a solution ... i m in urgent need of this


 
Old September 15th, 2007, 04:01 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Not a lot can be done there I doubt - your code just gets what its sent by the browser, and the browser just knows what its told from the OS, which certainly in windows relies heavily on file extension to map to mime type.

/- Sam Judson : Wrox Technical Editor -/
 
Old September 15th, 2007, 04:08 AM
Registered User
 
Join Date: Sep 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sauravnimesh
Default

Well....
One hint i got is when i check the Content type of a file by removing its Extension, it do suggest me the correct content type of file

Now the problem i am facing is, i dont know any way of checking the content type of file which id not picked up from browser control

if you can suggest any way for this ...i think the issue will resolve.


Thanks,
Saurav

Quote:
quote:Originally posted by samjudson
 Not a lot can be done there I doubt - your code just gets what its sent by the browser, and the browser just knows what its told from the OS, which certainly in windows relies heavily on file extension to map to mime type.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
users upload image mike7510uk ASP.NET 2.0 Basics 3 May 11th, 2007 08:16 AM
Upload pdf files yanis97 JSP Basics 3 April 23rd, 2007 11:43 PM
Combine rtf files with random access isnoend07 Pro VB 6 2 March 31st, 2007 01:22 PM
PDF and RTF from XML rajatake XML 2 March 28th, 2007 12:35 PM
hyperlinks of rtf files geetabajpai VB How-To 1 October 13th, 2005 04:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.