I have a method that uses Microsoft.Office.Interop.PowerPoint.Application interface to convert PowerPoint presentation slides into a jpeg files. In a serivce application that runs on Windows 2008 server it works without any issues.
Now however, I'm writing a new web application that uses the same process and the degubber chokes on the Presentation.Open call wiht an error: "PowerPoint could not open file".
My environment is Win 7, VS 2010. I'm using impersonation with a domain account that has admin privileges. The PowePoint file I'm trying to open is in the c:\temp folder which has NTFS rights of "everyone" set to full; file is NOT read-only, I can manually
opent the file using a similar account as the domain account I'm using for impersonation. I don't know what the problem is. Can someone sugest what's going on? Thanks, EJM.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
private static int folderExtension;
private static string tempSavePath,
fileName;
Although you can get your code to work by granting the user account under which your application is running the required permissions, you will always run into issues.
Hi, thanks for the post and the link to the article. I should share that I have this code running sucessfully in service application on the same server where it opens the PowerPoint in a non-interactive fashion and convert the slides into individual jpeg
files.
EJM
Member
190 Points
415 Posts
Opening a presentation file programatically throws an error.
Nov 16, 2012 09:57 PM|LINK
I have a method that uses Microsoft.Office.Interop.PowerPoint.Application interface to convert PowerPoint presentation slides into a jpeg files. In a serivce application that runs on Windows 2008 server it works without any issues.
Now however, I'm writing a new web application that uses the same process and the degubber chokes on the Presentation.Open call wiht an error: "PowerPoint could not open file".
My environment is Win 7, VS 2010. I'm using impersonation with a domain account that has admin privileges. The PowePoint file I'm trying to open is in the c:\temp folder which has NTFS rights of "everyone" set to full; file is NOT read-only, I can manually opent the file using a similar account as the domain account I'm using for impersonation. I don't know what the problem is. Can someone sugest what's going on? Thanks, EJM.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
private static int folderExtension;
private static string tempSavePath,
fileName;
protected void Page_Load(object sender, EventArgs e)
{
}
private void Page_Error(object sender, EventArgs e)
{
Random r = new Random();
int eventID = r.Next(1, 65535);
Exception objErr = Server.GetLastError().GetBaseException();
string err = "\nPage_Error Event" +
"\n\nError in: " + Request.Url.ToString() +
"\n\nError Message:" + objErr.Message.ToString() +
"\n\nStack Trace:" + objErr.StackTrace.ToString() +
"\n";
uploadResult.Text = err.ToString();
}
protected void AsyncFileUpload1_click(object sender, AsyncFileUploadEventArgs e)
{
// Temporary folder where the presentation file is uploaded.
tempSavePath = @"c:\temp\";
// Checks if there is a file present for uploading.
if (AsyncFileUpload1.HasFile)
{
fileName = AsyncFileUpload1.FileName;
try
{
AsyncFileUpload1.SaveAs(tempSavePath + fileName);
}
catch (Exception ex)
{
throw ex;
}
finally
{
ConvertToJpegs();
}
}
else
{
uploadResult.Text = "No file to upload.";
}
}
// Converts the presentation slides into individual jpeg files.
protected void ConvertToJpegs()
{
Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue;
Presentation pptPresentation = null;
try
{
**>>> It break here with the ".Open" call <<<**
pptPresentation = app.Presentations.Open(tempSavePath + fileName, ofalse, ofalse, ofalse);
pptPresentation.SaveAs(tempSavePath + ".", PpSaveAsFileType.ppSaveAsJPG, ofalse);
Thread.Sleep(500);
}
catch (Exception ex1)
{
throw ex1;
}
finally
{
pptPresentation.Close();
}
}
}
Prashant Kum...
Star
12346 Points
1993 Posts
Re: Opening a presentation file programatically throws an error.
Nov 17, 2012 12:17 AM|LINK
Opening office documents in a web application is not recommended and not supported by Microsoft.
http://support.microsoft.com/kb/257757
Although you can get your code to work by granting the user account under which your application is running the required permissions, you will always run into issues.
EJM
Member
190 Points
415 Posts
Re: Opening a presentation file programatically throws an error.
Nov 17, 2012 03:12 PM|LINK
Hi, thanks for the post and the link to the article. I should share that I have this code running sucessfully in service application on the same server where it opens the PowerPoint in a non-interactive fashion and convert the slides into individual jpeg files.