views:

15

answers:

1

I've narrowed down the issue I'm having to this block of code, where I am resizing an uploaded image and saving it. This works fine on my local machine, but when I run the site on the server, I get a generic GDI+ error that's coming from the "thumbnail.Save" call.

if(fup_displayPicUpload.HasFile)
            {
                string imageDir = Server.MapPath("./images/");

                if (!Directory.Exists(imageDir + username))
                {
                    Directory.CreateDirectory(imageDir + username);
                    lbl_profileMessage.ForeColor = Color.Yellow;
                    lbl_profileMessage.Text = "Created User Folder";
                }
                String userFolder = imageDir + username + "/";

                using (System.Drawing.Image originalPhoto = new Bitmap(new MemoryStream(fup_displayPicUpload.FileBytes)))
                {
                    System.Drawing.Image thumbnail = originalPhoto.GetThumbnailImage(300, 300, Abort, IntPtr.Zero);
                    thumbnail.Save(userFolder + "displaypicture.jpg", ImageFormat.Jpeg);
                }

                displayPictureUrl = "/images/" + username + "/displaypicture.jpg";

            }
+1  A: 

The most common cause of this is an access denied error to the directory that you are trying to save the image to. Make sure that the user that the application is running as has write access to the destination directory.

Mike
You are most certainly right, I was trying to set the permissions using FileZilla but they were being overridden by the hosting manager. Thanks!
Gallen