Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 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, 04:02 AM
Registered User
 
Join Date: Sep 2007
Location: delhi, delhi, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sauravnimesh
Default upload doc or pdf only

hi All,

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

code i m using

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, 05:43 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

As you are experiencing, the content type of the uploaded file is determined by the file extension.

The only solution I can think of would be to read the file to determine if is the one of the desired type. You could try to load the file in the appropriate application (word, adobe reader) and determine if the file loaded successfully. If not, then you could assume it is not a valid format for that extension.

-Peter
 
Old September 16th, 2007, 11:33 PM
Registered User
 
Join Date: Sep 2007
Location: delhi, delhi, India.
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.


is there any way i can get code for implementing browse control manually??:(

Thanks,
Saurav




Similar Threads
Thread Thread Starter Forum Replies Last Post
doc to pdf/image using java aditya_a7 J2EE 3 January 5th, 2010 09:50 AM
Using XSL to generate single pdf doc bhavanimachani XML 2 March 24th, 2008 11:57 PM
doc to pdf converter crmpicco Classic ASP Basics 3 February 23rd, 2005 11:25 PM
upload doc,pdf file from ORACLE 9i on JSP page ashwinmittal Pro JSP 1 November 30th, 2004 01:18 PM





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