GDI+ A generic error … Attempting to save file

天大地大妈咪最大 提交于 2019-12-14 03:58:41

问题


I've been learning quite a bit from everyone here, however I've come across a problem which I'm having trouble finding an answer to. While attempting to save an image which has been uploaded using AsyncFileUpload I'm receiving the following error: A generic error occurred in GDI+.

I've done quite a bit of Googling and it seems that the most likely issue is permissions related. I've tried allowing write/modify for Network and Network_Serice. Later attempted allowing it for the environment user and finally tested it with "Everyone" - unfortunately it was still not working.

One possible issue is the fact that I'm relying on the built-in development server. I'm still fairly new to it all, so not too sure if there are any limitations in this area or if I'm simply overlooking something obvious.

Code:



try
{
     //Attempt to convert file to image
     uploadedImage = System.Drawing.Image.FromStream(avatarUpload.PostedFile.InputStream);

     //Save image
     if (uploadedImage != null)
     {
          //Create vars
          String savePath = Server.MapPath("~/Images/Avatars/");

          //Save image
          uploadedImage.Save(savePath, ImageFormat.Jpeg); !!! Exception raised here

          //Dispose of image
          uploadedImage.Dispose();
     }
}
catch
{
     //Create error message
     createMessage("Please ensure you select an image i.e. .bmp, .png, .jpg.", "error");
}                                   

If anyone has any ideas or needs any more info please let me know.


回答1:


Change

String savePath = Server.MapPath("~/Images/Avatars/");

To

String savePath = Server.MapPath("~/Images/Avatars/myImage.jpg");


来源:https://stackoverflow.com/questions/5714241/gdi-a-generic-error-attempting-to-save-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!