programad
programad

Reputation: 1311

Saving images on the server

I'm getting the "generic error occurred on GDI++ wen trying to save images.

What I am missing here?

string appdatapath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();

if (!Directory.Exists(appdatapath + "/Images")
    Directory.CreateDirectory(appdatapath + "/Images", Directory.GetAccessControl(appdatapath));

if (!Directory.Exists(appdatapath + "/Images/XBLContent/"))
                Directory.CreateDirectory(appdatapath + "/Images/XBLContent/", Directory.GetAccessControl(appdatapath));

string imagesdir = Path.Combine(appdatapath, "/Images/XBLContent/");

Image image = FeedUtils.RequestImage(String.Format({0}/{1}/image.jpg", url, c.GUID));

image.Save(imagesdir + c.GUID + "sm.jpg");

Upvotes: 0

Views: 1005

Answers (1)

brodie
brodie

Reputation: 5434

Check whether your IIS worker process has write permissions to the local file system, and in particular the folder whether you are saving the image.

Also, use Server.MapPath() to get the physical location.

See this blog for a solution.

Upvotes: 1

Related Questions