0

I am getting an error (A generic error occurred in GDI+.) when I try to replace images from a folder .It works fine when it runs in localhost.

Here is my Code :

    if (FuBannerImg2.HasFile)
    {
        int width = 1920;
        int height = 1280;
        Stream stream = FuBannerImg2.PostedFile.InputStream;

        Bitmap image = new Bitmap(stream);

        Bitmap target = new Bitmap(width, height);
        Graphics graphic = Graphics.FromImage(target);
        graphic.DrawImage(image, 0, 0, width, height);
        target.Save(Server.MapPath("~/img/bg-img/bgimg1.jpg"));
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "clientScript", "alert('Image uploaded Successfully')", true);
        fillhome();

;

enter image description here

Jackwin
  • 26
  • 2
  • 2
    Please share some details about the error that you encountered and clarify which line throwed it. – Lajos Arpad Aug 10 '22 at 12:43
  • Consider updating the code with something a bit more "complete" than just a fragment - consider a private method for the code in the condition to make it more S in SOLID to make Uncle Bob followers more satisfied. – Mark Schultheiss Aug 10 '22 at 14:14
  • Did you get a stack trace? If so what does that tell you? Similar https://stackoverflow.com/q/10425430/125981 and https://stackoverflow.com/q/54715109/125981 Note this is likely not a great choice for use on "not localhost" which probably means a server/service here? When it is more a desktop thing. i.e. big pink caution here: https://learn.microsoft.com/en-us/dotnet/api/system.drawing?redirectedfrom=MSDN&view=net-6.0 – Mark Schultheiss Aug 10 '22 at 14:26
  • It throwed in this line Line 181: target.Save(Server.MapPath("~/img/bg-img/bgimg.jpg")); – Jackwin Aug 11 '22 at 04:18
  • For stack trace i have added a screen shot of the error in the above post ..do check it – Jackwin Aug 11 '22 at 04:20

0 Answers0