I have a program in asp.Net MVC. My server is plesk.
I save my files using this method:
public string SaveFile(HttpPostedFileBase file, string path)
{
string fileName = Guid.NewGuid() + file.FileName;
var filePath = Path.Combine(Server.MapPath("~/Images/"), fileName);
file.SaveAs(filePath);
return fileName;
}
and file saving is OK in test computer. But after uploading on server I get this error:
Could not find a part of the path 'C:\Inetpub\vhosts\hostname.com\mysitename.com\Images\myFile.jpg'
What is wrong with my code? Should I use something different when using plesk?
OK then, most likely it is because your IIS user does not have write permission to write on that folder. Add full permission on the folder. The user must be something like: Plesk IIS WP User
.
You can simply allow write/modify permission for subscription in Hosting Settings: