Wrox Programmer Forums
|
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 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 August 27th, 2013, 10:25 PM
Authorized User
 
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
 
Old August 28th, 2013, 01:46 PM
Authorized User
 
Join Date: Jun 2013
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)





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





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