Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public ActionResult UploadImageWithRetry()
{
List<httppostedfilebase> errorfiles = (Session["errorList"]) as List<httppostedfilebase>;
if (errorfiles != null)
{
foreach (HttpPostedFileBase file in errorfiles)
{

if (CheckImageType(file))
{
if (CheckImageSize(file))//call from here
{

}
}
}
}
}
}


C#
public bool CheckImageSize(HttpPostedFileBase aFile)
        {
            bool isValid = false;
            if (aFile.ContentLength > 0)
            {
                try
                {
                    System.Drawing.Image imageObj = System.Drawing.Image.FromStream(aFile.InputStream); //error generated here
                    if ((imageObj.Width == 640 && imageObj.Height == 960) || (imageObj.Width == 640 && imageObj.Height == 1136) || (imageObj.Width == 768 && imageObj.Height == 1024) || (imageObj.Width == 1536 && imageObj.Height == 2048))
                    {
                        isValid = true;
                    }
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            return true;
        }
Posted
Comments
Krunal Rohit 2-Mar-14 6:17am    
improve the question first.

-KR
suzand 2-Mar-14 6:25am    
Session contain several object of httppostedfilebase, sometime error is not generated for the first one object. I'm being frustrated by facing this weird exception.
Please help me!!! what should i do...........

Thanks in advance.

1 solution

"Parameter Not Valid" is a generic error message from the GDI, which basically means "that isn't an image I recognise"

The most obvious reason is that whatever file you are trying to upload is not a valid image file, or is corrupt or incomplete.
Try saving the stream data in a temporary file, and examine it manually to see what kind of data the stream contains.
 
Share this answer
 
Comments
suzand 2-Mar-14 6:56am    
I stored list of object in session from a action method and retrieve from different action method. Using quick watch i can view all file information even file.InputStream.length, position, file name etc.

I've uploaded several image to flickr by checking image size, those are not uploaded(for network connection problem, willingly created.)are shown in the form of list in different view with Retry button and before call view list of objece(those are not uploaded in flickr)is stored in session. And when i click on that button sometime first image file of session variable uploaded in flickr properly, most of the time it throw that exception. Now if you give me a reference/code that will be more appreciated.
Thanks a lot
suzand 3-Mar-14 2:31am    
Thanks @OriginalGriff
I've tried the way you shown. I found what the problem is, "ObjectDisposedException was Caught"
I think this means file is closed.
Now how it can be reopen???

Please give me your valuable suggestion.

Thanksssssssssssssssss

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900