I have an application that posts database data to PowerPoint slide templates. One of the slides requires a picture as well. The following adds the picture to the slide:
public void InsertImageInSlide()
{
string SNMPicName = Session["SNMName"].ToString().Trim().Replace(" ", "_");
Session["SNMPicName"] = SNMPicName;
string strImgPath = "C:\\SNMPics\\" + SNMPicName + ".jpg";
if (File.Exists(strImgPath))
{
Microsoft.Office.Interop.PowerPoint.Application ppApp;
Microsoft.Office.Interop.PowerPoint.Presentation ppPrsn;
Microsoft.Office.Interop.PowerPoint.Slide objSlide;
Microsoft.Office.Interop.PowerPoint.Shape objShape;
Microsoft.Office.Core.MsoTriState msoCFalse = Microsoft.Office.Core.MsoTriState.msoFalse;
Microsoft.Office.Core.MsoTriState msoCTrue = Microsoft.Office.Core.MsoTriState.msoTrue;
string strTemplateFile;
ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
strTemplateFile = Session["pptxPowerpoint"].ToString().Trim();
ppPrsn = ppApp.Presentations.Open(strTemplateFile);
objSlide = ppApp.ActiveWindow.Presentation.Slides[1];
objShape = ppPrsn.Slides[1].Shapes.AddPicture(strImgPath, msoCFalse, msoCTrue, 500, 150, 200, 250);
ppPrsn.Save();
ppPrsn.Close();
}
}
In a VS2012 run without debugging, this code successfully adds the picture to the slide. However when the code is published to an IIS7 server, the code produces the following error when the application is invoked:
PowerPoint could not open the file.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: PowerPoint could not open the file.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[COMException (0x80004005): PowerPoint could not open the file.]
Microsoft.Office.Interop.PowerPoint.Presentations.Open(String FileName, MsoTriState ReadOnly, MsoTriState Untitled, MsoTriState WithWindow) +0
PowerPointTemplate.InsertImageInSlide() +631
PowerPointTemplate.ParseTemplate() +1572
GeneratePowerPoint.ProcessAllSlides() +534
GeneratePowerPoint.BuildBriefSlides() +5159
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
The error occurs in the line containing AddPicture where PowerPoint cannot open the picture file. Any ideas?