I am trying to add an image (.png) to a prexisting powerpoint template.
this is the code that i'm using:
I keep getting an error on the last line.
---------------------------------------------------------------------------
string CustomerPowerPointPath = HttpContext.Current.Server.MapPath("~") + "\\Templates\\" + "PlanningTemplate.ppt";
string CustomerSnapShotPath = HttpContext.Current.Server.MapPath("~") + "\\Templates\\" + "test.png";
// create powerpoint object
Presentation objPresentation = new Presentation(CustomerPowerPointPath);
Picture objPicture = new Picture(objPresentation, CustomerSnapShotPath);
int count = objPresentation.Pictures.Count;
int objPictureID = objPresentation.Pictures.Add(objPicture);
count = objPresentation.Pictures.Count;
int pictureWidth = objPresentation.Pictures[count-1].Image.Width;
int pictureHeight = objPresentation.Pictures[count-1].Image.Height;
Slide objSlide = objPresentation.GetSlideByPosition(10);
int slideWidth = objSlide.Background.Width;
int slideHeight = objSlide.Background.Height;
int pictureFrameWidth = Convert.ToInt32(slideWidth/2 - pictureWidth/2);
int pictureFrameHeight = Convert.ToInt32(slideHeight/2 - pictureHeight/2);
PictureFrame objPictureFrame = objSlide.Shapes.AddPictureFrame(objPictureID, pictureFrameWidth, pictureFrameHeight, pictureWidth, pictureHeight);
HttpContext.Current.Response.ContentType = "application/vnd.ms-powerpoint";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=demo.ppt");
HttpContext.Current.Response.Flush();
System.IO.Stream objStream = HttpContext.Current.Response.OutputStream;
objPresentation.Write(objStream);
HttpContext.Current.Response.End();