I'm working on a solution in which at some part I need to convert uploaded image into the base 64 string, My code is working fine on localhost but when I upload it to the server it's giving me Access to the path'C:\Inetpub\vhosts\xyz.com\xyz.com\Resources\Address\1002055.jpg' is denied.
Here is my code snippet,
strFileName = fuPhoto.FileName;
strFileExtension = Path.GetExtension(fuPhoto.FileName);
if (strFileExtension.ToLower() == ".jpg" || strFileExtension.ToLower() == ".jpeg" || strFileExtension.ToLower() == ".png")
{
CSPProfileFile = Functions.GetFileName(hdnCSPCode.Value + strFileExtension);
fuPhoto.SaveAs(Server.MapPath(Path.Combine("~/Resources/Profile/", CSPProfileFile)));
base64_photo = ConvertToBase64Image(Server.MapPath("~/Resources/Profile/"+CSPProfileFile));
}
and I used a simple base64 string conversion method
internal static string ConvertToBase64Image(string file)
{
return Convert.ToBase64String(File.ReadAllBytes(file));
}
This code works fine on localhost environment but when I published it to server I got an error- Access to the path'C:\Inetpub\vhosts\xyz.com\xyz.com\Resources\Address\1002055.jpg' is denied.
previously same code was working fine on the server also, did I code something wrong..