我有一种使用 Microsoft.Office.Interop.PowerPoint.Application 接口将 PowerPoint 演示文稿幻灯片转换为 jpeg 文件的方法。在 Windows 2008 服务器上运行的服务应用程序中,它可以正常工作。
但是,现在我正在编写一个新的 Web 应用程序,它使用相同的进程,并且 Presentation.Open 调用上的 degubber 阻塞并出现错误:“PowerPoint 无法打开文件”。
我的环境是 Win 7,VS 2010。我正在使用具有管理员权限的域帐户进行模拟。我试图打开的 PowePoint 文件位于 c:\temp 文件夹中,该文件夹的“所有人”的 NTFS 权限设置为完整;文件不是只读的,我可以使用与我用于模拟的域帐户类似的帐户手动打开文件。我不知道问题是什么。有人可以建议发生了什么吗?
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();
}
}
}