Home Ask Login Register

Developers Planet

Your answer is one click away!

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

 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)));
         tempname = photo.FileName;
     string fname = tempname;
     imagePath = Server.MapPath("~/Content/Temp/") + fname;
     photo.Resize(photo.Width, 300, true);
     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


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

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

Then retrieve it using


Post Status

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


Leave an answer

Quote of the day: live life