0

So here is the problem. i am saving images in binary form to db. In the WCF service i created I want to save the file to a folder within the project i.e (/Images).

I normally use this code

 //picbin is binary image data fetched from db
 ImageConverter ic = new ImageConverter();
 System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(picbin);
 img.Save(HttpContext.Current.Server.MapPath(imagePath + picture_id + ".Jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg);// imagePath ="Images/"

The problem is HttpContext.Current.Server.MapPath does not work in WCF services. so how can I get the physical path to save the image. Also what Url can i Get to access the image

I tried Using HostingEnvironment.MapPath, but the path it returns is always null.

Sujit.Warrier
  • 2,815
  • 2
  • 28
  • 47
  • Possible duplicate of [How to MapPath with RequestContext in WCF Service](http://stackoverflow.com/questions/10384894/how-to-mappath-with-requestcontext-in-wcf-service) – Jan Köhler Apr 20 '16 at 05:18

2 Answers2

0

You can use HostingEnvironment.MapPath.

please check below link

https://stackoverflow.com/a/10384987/2699211

Community
  • 1
  • 1
Hadi
  • 443
  • 3
  • 15
  • cant use that as it says hostring environment does not exist in the current context. i tried including System.Web.Hosting it does not recognize it – Sujit.Warrier Apr 20 '16 at 05:19
  • 1
    I get null as path id i use HostingEnvironment.MapPath – Sujit.Warrier Apr 20 '16 at 06:19
  • in the below link solved your problem . please check that http://stackoverflow.com/questions/791468/how-to-get-working-path-of-a-wcf-application – Hadi Apr 20 '16 at 06:20
0

img.Save("website absolute path/" +(imagePath + picture_id + ".Jpeg"),

you need to provide the absolute path. it works on my side.