I have a dialog box in a C# Winforms application. I want to save images. But each time I click on the save button, I get an error
A generic error occurred in gdi+
This is my code for saving the image:
var SavedFileName = string.Format(@"{0}.png", Guid.NewGuid());
var path = Application.StartupPath + "/passport/" + SavedFileName.ToString();
if(passportsize.Image == null)
{
SavedFileName = "";
}
else
{
passportsize.Image.Save(path,System.Drawing.Imaging.ImageFormat.Png);
}
.ToStringonSavedFileNameis redundant since it is already a string. And I would recommend usingPath.Combineto construct the file path. Specificallyvar path = Path.Combine(Application.StartupPath, "passport", SavedFileName);. Are you using Linux or Windows?Application.StartupPathis a very bad place to try to save a file; it's probably not writable by non-admins, and will get deleted if you uninstall or repair your application. Save user data inEnvironment.GetFolderPath(Environment.SpecialFolder.ApplicationData).