Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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

Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:24 PM.


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