Error: A Generic Error occurred in GDI+

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uday1302
    New Member
    • Mar 2008
    • 18

    Error: A Generic Error occurred in GDI+

    Hi Dear,

    Here I am trying to upload a photo.

    Code:
    protected void LoadImage()        {
                string UserName = Session["UserName"].ToString();
    
                byte[] Data = Profile.GetImageData(UserName); //Stmt Correct where profile is class
               
                if (Data != null)
                {
                    MemoryStream stream = new MemoryStream(Data);
    
                    Bitmap bitmap = null;
                    bitmap = new Bitmap(stream);
    
                    bitmap.Save(Server.MapPath(@"~\UserPhoto.bmp"), system.Drawing.Imaging.ImageFormat.Bmp); 
                    //Error:A Generic   Error occurred in GDI+            
                    bitmap.Dispose();
                    imgPhoto.ImageUrl = @"~\UserPhoto.bmp";            }     }

    I have created virtual directory and trying to open it directly from browser
    Last edited by tlhintoq; Dec 29 '09, 05:36 PM. Reason: [coDE] ...Your code goes between code tags [/CODE]
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    I think the problem occurs while opening up your virtual directory as you have earlier used Server.MapPath( );

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Code:
        bitmap.Save(Server.MapPath(@"~\UserPhoto.bmp"), system.Drawing.Imaging.ImageFormat.Bmp);
        I don't see any error checking.
        What if you don't have write permissions to the directory?
        What if an image of that name already exists in the directory?
        Are you sure the MapPath function with that string literal is valid and not something like: Server\Userfold er\~\UserPhoto. bmp

        Comment

        Working...