I have a very simple requirement, there's a folder containing an image file, I have a form with only one upload field to select an image and save it with the same existing image name to overwrite it
protected void ChangeLogo(object sender, EventArgs e)
{
if (!ImageUpload.HasFile)
{
ShowPopup("Logo Upload Canceled", "Please upload the image for the logo.", "stop");
}
else //save the image
{
string logoPath = Server.MapPath("~/images/home/");
string filename = "logo.png";
ImageUpload.SaveAs(logoPath + filename);
}
}
I am getting an error: Access to the path 'C:\inetpub\wwwroot\website\images\home\logo.png' is denied even though there's full access control on the folder but if i saved it with a different name it works, it only refuses to overwrite and I need to overwrite. I thought of first deleting the image then saving, but this is silly, why can't I overwrite?
Thanks in advance
Naive solution:
If(File.Exists(logoPath + filename))
File.Delete(logoPath + filename);
ImageUpload.SaveAs(logoPath + filename);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With