This is a migrated thread and some comments may be shown as answers.

validate the size of a jpg image in pixels.

2 Answers 195 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
ALBERT
Top achievements
Rank 1
ALBERT asked on 16 May 2012, 03:22 PM
the only thing I could validate the size of the option MaxFileSize. I have to validate to upload a photo that is 96x96 pixels. How do I can do?.

Thanks for your help

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 May 2012, 02:35 PM
Hello Albert,

Try the following code to achieve your scenario.
aspx:
<telerik:RadUpload ID="RadUpload1" runat="server" AllowedFileExtensions=".jpg"></telerik:RadUpload>
<asp:Button ID="Button1" runat="server" Text="j" onclick="Button1_Click" />
C#:
protected void Button1_Click(object sender, EventArgs e)
{
 if (RadUpload1.UploadedFiles.Count > 0)
 {
   foreach (UploadedFile theFile in RadUpload1.UploadedFiles)
   {
     System.Drawing.Image myImage = System.Drawing.Image.FromStream(theFile.InputStream);
     if (myImage.Width > 96 || myImage.Height > 96)
     {
         Response.Write("<script>alert('Large image');</script>");
     }
   }
 }
}

Thanks,
Shinu.
0
ALBERT
Top achievements
Rank 1
answered on 17 May 2012, 08:21 PM
perfect. Thank you very much for your help
Tags
Upload (Obsolete)
Asked by
ALBERT
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ALBERT
Top achievements
Rank 1
Share this question
or