Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save

Scheduled Pinned Locked Moved C#
graphicssysadminhelpwinforms
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uglyeyes
    wrote on last edited by
    #1

    Hi, I am trying to upload an image and resize it. the image being uploaded will be saved in photos and thumbs directory. I have given network service and iusr_machinename write access to both folders. the upload works fine in local machine its just when i try to upload via a remote server i get error "A generic error occurred in GDI+." below are my codes for upload click event. please help

    try
    {
    String file = "";
    String thumb = "";
    if (flUpload.PostedFile.ContentLength > 0)
    {
    file = flUpload.FileName;
    thumb = "";
    String[] strNew = file.Split('.');
    strNew[0] = DateTime.Now.Ticks.ToString();
    file = strNew[0] + "." + strNew[1];
    thumb = strNew[0] + "_t." + strNew[1];

                        ImageName = file;
                        ImagePath = Server.MapPath("~/photos") +"\\\\"+ ImageName;
                        Response.Write(ImagePath);
    
                        ImageThumbName = thumb;
                        ImageThumbPath = Server.MapPath("~/thumbs") + "\\\\" + ImageThumbName;
                        Response.Write(ImageThumbPath);
    
                       
                        using (System.Drawing.Image Img = new Bitmap(flUpload.FileContent))
                        {
                            Size ThumbNailSize = NewImageSize(Img.Height, Img.Width, 100);
                            Size ImageSize = NewImageSize(Img.Height, Img.Width, 500);
    
                            using (System.Drawing.Image ImgThnail = new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
                            {
                                ImgThnail.Save(ImageThumbPath, Img.RawFormat);
                                ImgThnail.Dispose();
                            }
                            using (System.Drawing.Image Img1 = new Bitmap(Img, ImageSize.Width, ImageSize.Height))
                            {
                                Img1.Save(ImagePath, Img.RawFormat);
                                Img1.Dispose();
                            }
                            Img.Dispose();
                        }
                    }
    

    public Size NewImageSize(int OriginalHeight, int OriginalWidth, double FormatSize)
    {
    Size NewSize; double tempval;

            if (OriginalHeight > FormatSize &a
    
    A 1 Reply Last reply
    0
    • U uglyeyes

      Hi, I am trying to upload an image and resize it. the image being uploaded will be saved in photos and thumbs directory. I have given network service and iusr_machinename write access to both folders. the upload works fine in local machine its just when i try to upload via a remote server i get error "A generic error occurred in GDI+." below are my codes for upload click event. please help

      try
      {
      String file = "";
      String thumb = "";
      if (flUpload.PostedFile.ContentLength > 0)
      {
      file = flUpload.FileName;
      thumb = "";
      String[] strNew = file.Split('.');
      strNew[0] = DateTime.Now.Ticks.ToString();
      file = strNew[0] + "." + strNew[1];
      thumb = strNew[0] + "_t." + strNew[1];

                          ImageName = file;
                          ImagePath = Server.MapPath("~/photos") +"\\\\"+ ImageName;
                          Response.Write(ImagePath);
      
                          ImageThumbName = thumb;
                          ImageThumbPath = Server.MapPath("~/thumbs") + "\\\\" + ImageThumbName;
                          Response.Write(ImageThumbPath);
      
                         
                          using (System.Drawing.Image Img = new Bitmap(flUpload.FileContent))
                          {
                              Size ThumbNailSize = NewImageSize(Img.Height, Img.Width, 100);
                              Size ImageSize = NewImageSize(Img.Height, Img.Width, 500);
      
                              using (System.Drawing.Image ImgThnail = new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
                              {
                                  ImgThnail.Save(ImageThumbPath, Img.RawFormat);
                                  ImgThnail.Dispose();
                              }
                              using (System.Drawing.Image Img1 = new Bitmap(Img, ImageSize.Width, ImageSize.Height))
                              {
                                  Img1.Save(ImagePath, Img.RawFormat);
                                  Img1.Dispose();
                              }
                              Img.Dispose();
                          }
                      }
      

      public Size NewImageSize(int OriginalHeight, int OriginalWidth, double FormatSize)
      {
      Size NewSize; double tempval;

              if (OriginalHeight > FormatSize &a
      
      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Check if you have access rights to save to the shared / network folder.

      There are only 10 types of people in this world — those who understand binary, and those who don't.

      U 1 Reply Last reply
      0
      • A Abhinav S

        Check if you have access rights to save to the shared / network folder.

        There are only 10 types of people in this world — those who understand binary, and those who don't.

        U Offline
        U Offline
        uglyeyes
        wrote on last edited by
        #3

        what do you mean. not sure how i do that as the website is hosted remotely and its with the hosting provider.

        U 1 Reply Last reply
        0
        • U uglyeyes

          what do you mean. not sure how i do that as the website is hosted remotely and its with the hosting provider.

          U Offline
          U Offline
          uglyeyes
          wrote on last edited by
          #4

          anyone?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups