I have an asp.net project and I am saving selected image to NewUrunler1 file and I am saving image's path in my database. In local, it works without a problem but since I moved my project to my godaddy host, saving method gives an error. Here is my code to save image:
protected void UploadImage()
{
try
{
HttpPostedFile yuklenecekDosya = FileUploadImage.PostedFile;
if (yuklenecekDosya != null)
{
FileInfo dosyaBilgisi = new FileInfo(yuklenecekDosya.FileName);
string yuklemeYeri = Server.MapPath("~/Images/NewUrunler1/" + dosyaBilgisi);
FileUploadImage.SaveAs(Path.Combine(yuklemeYeri));
}
}
catch (Exception e)
{
failDiv.Visible = true;
lblHata.Text = e.ToString();
}
}
When I run this I get an error from try catch. Here is the error:
System.UnauthorizedAccessException: Access to the path 'G:\PleskVhosts\ada-crm.com\httpdocs\Images\NewUrunler1\deneme.png' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at CRM.UrunEkle.UploadImage()
I am new in asp.net so sorry if it is an easy question but I searched in web and couldn't solve it. Thank you for your time.
I am not sure about GoDaddy but in a typical IIS hosted environment, you need to ensure that the folder you are attempting to upload to has Write permission applied to it for the User which is associated with the ApplicationPool of the website.
Also, make sure the path exists first. You can do this by checking whether the folders exist and then creating them if they do not.