Search code examples
c#azuresystem.drawing

File storage in azure. A generic error occured in GDI+


I'm saving file as:

var i2 = new Bitmap(image);
i2.Save(Server.MapPath(@"~\Images\Ads\" + filename));

I'm getting error:

"System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename)

How can I check that Images and Ad folders exist?

And where my images are saved? Can I see Ad directory and all files in it?

Note: I want to use azure simple file storage to store files temporary. I don't want to use azure blob.


Solution

  • I was getting his error because my Ads directory does not exist.

    Azure does not create directories by itself, if it does not exist. I simply used this:

        Directory.CreateDirectory(Server.MapPath(@"~\Images\Ads\");
    

    It creates a directory if it does not exist.