shaik.jameer February 2016

How do I save image in database in published application using C # in mvc

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

Answers


Mir February 2016

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"];

Post Status

Asked in February 2016
Viewed 3,210 times
Voted 8
Answered 1 times

Search




Leave an answer