0

I think ajaxcontroltoolkit:ajaxfileupload has too many bugs and wane. since I'm using this component frequently in my projects, I overcome to many serious disturbing bugs and functionality of this control. Now, I seriously need to get uploaded image width and height using ajaxfileupload before I save it to check either width or height are correct and based on retrieved information, informing users in case of image width and height are not compatible and then prevent the process to go further and save the picture. Any Ideas please?!

HTML Side:

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
        onuploadcomplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="1" AllowedFileTypes="jpg,jpeg"/>

Behind Code:

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
    string filePath = "~/upload/" + e.FileName;
    AjaxFileUpload1.SaveAs(filePath);

}
2
  • Can you show the prototype for the method that accepts this file upload? Commented Dec 3, 2012 at 4:29
  • Sure, I edited my question Simon and added the code there... thank you for your concern. Commented Dec 3, 2012 at 6:19

1 Answer 1

6

AjaxFileUpload just handles the upload but doesn't give you any information about the file itself. You need to use something like

System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath(filePath));
width = objImage.Width;
height = objImage.Height; 

If you do not want to load the file into memory, you can check How do I reliably get an image dimensions in .NET without loading the image? or Getting image dimensions without reading the entire file.

An alternative would be to check image width and height on client side, using a tool like Plupload or a similar one.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. but, don't u think that it makes some overload on server side?
Why don't you jut try and see if it works? These are the only ways. The solutions in the links cost less memory and CPU but don't work for all image types. I have added an alternative, but then you wouldn't use AjaxFileUpload.
Ok, mate... thank you very much... I'll give u update after I finished work around it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.