Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB 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 August 27th, 2013, 10:25 PM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
Default extensions

how to allow multiple image extensions and limit the size of an image to 2 MB
Reply With Quote
  #2 (permalink)  
Old August 28th, 2013, 01:46 PM
Authorized User
Points: 175, Level: 3
Points: 175, Level: 3 Points: 175, Level: 3 Points: 175, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Location: St.Petersburg, Russia
Posts: 36
Thanks: 1
Thanked 4 Times in 4 Posts
Default

Do you mean you want to upload the images from the page up to your server?

You can use <asp:FileUpload> control + <asp:Button>
There are plenty of examples how to do it:

Code:
if (FileUpload1.HasFile) {

string fileName = Server.HtmlEncode(FileUpload1.FileName);
string extension = System.IO.Path.GetExtension(fileName);
if ((extension == ".jpg" )|| (extension == ".png"))
FileUpload1.SaveAs(MapPath("~/Uploads/" + FileUpload1.FileName));
}
Checking the file size is tricky: as of now, I think, you cannot use HTML5 File API (http://dev.w3.org/2006/webapi/FileAPI/) and it means you cannot find out the file size before you upload the file to your server.
However, the common solution is to limit the request size in <httpRuntime maxRequestLength="2048" /> (2Mb)
If the uploaded file is bigger than the allowed request - ASP.NET will reject it (but you will have to handle the error)
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
Forum Extensions plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 130 November 24th, 2009 07:10 PM
Some Extensions plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 29th, 2008 11:57 AM
File Extensions nbnelson C# 2 August 25th, 2003 12:09 PM



All times are GMT -4. The time now is 07:29 AM.


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