0

I upload company logo in application,It's working but when i publish and check it getting error

here is post method of image

[HttpPost]
 public string Logo()
 {
     WebImage photo = null;
     var imagePath = "";
     photo = WebImage.GetImageFromRequest();

     string tempname = "";
     if (photo.FileName.Contains("\\"))
     {
         tempname = photo.FileName.Substring((photo.FileName.LastIndexOf("\\") + 1), (photo.FileName.Length - (photo.FileName.LastIndexOf("\\") + 1)));
     }
     else
     {
         tempname = photo.FileName;
     }
     string fname = tempname;
     imagePath = Server.MapPath("~/Content/Temp/") + fname;
     photo.Resize(photo.Width, 300, true);
     photo.Save(imagePath);
     return "<img src='/Content/Temp/" + fname + "'  class='preview' id='targetimage' >";
 }

i am getting this error System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\SCL Mngmnt Test Link_08_Feb\Content\Temp\Desert.jpg' is denied

shaik.jameer
  • 1
  • 2
  • 5

1 Answers1

0

Publish somewhere else except c drive (That have permission)

Better define a global variable in your Web config which will hold the path you want to save image .

That is how you will be able to change the path anytime you want.

Here is how you can set in web.config

<appSettings>
     <add key="ImagePath" value="YourImageSavingPath"/>
  </appSettings>

Then retrieve it using

 path=System.Configuration.ConfigurationManager.AppSettings["ImagePath"];
Mir Gulam Sarwar
  • 2,400
  • 2
  • 24
  • 39