convert svg to image programmatically

I made a couple of changes to you code here: I think InkScape was having a problem with you paths, you'd used

PngRelativeDirectory + "\" + pngFileName

PngRelativeDirectory already had a "\" in it so the path was coming our as c:\\sample.png

Also i changed the Context.RewritePath to Response.Redirect - I get the pie chart rendered in the browser the browser.

string svgFileName = HttpContext.Current.Server.MapPath("sample.svg");
string PngRelativeDirectory = "C:\\";
string pngName = "svgpieresult.png";
string pngFileName = HttpContext.Current.Server.MapPath(pngName);


/* ignored assume sample.svg is in the web app directory
using (StreamWriter writer = new StreamWriter(svgFileName, false))
{
    writer.Write(svgXml);
}
 */

string inkscapeArgs = string.Format(@"-f ""{0}"" -e ""{1}""", svgFileName, pngFileName);

Process inkscape = Process.Start(
  new ProcessStartInfo( "C:\\Program Files\\inkscape\\inkscape.exe", inkscapeArgs));

inkscape.WaitForExit(3000);
//Context.RewritePath(pngName);
this.Response.Redirect(pngName);

Tags:

C#

Image

Svg