Microsoft.Office.Interop.PowerPoint.Application インターフェイスを使用して PowerPoint プレゼンテーション スライドを jpeg ファイルに変換する方法があります。Windows 2008 サーバーで実行されるサービス アプリケーションでは、問題なく動作します。
しかし、現在、同じプロセスを使用する新しい Web アプリケーションを作成しており、degubber が Presentation.Open 呼び出しで「PowerPoint はファイルを開けませんでした」というエラーでチョークします。
私の環境は Win 7、VS 2010 です。管理者権限を持つドメイン アカウントで偽装を使用しています。私が開こうとしている PowePoint ファイルは、「全員」の NTFS 権限が完全に設定されている c:\temp フォルダーにあります。ファイルは読み取り専用ではありません。なりすましに使用しているドメイン アカウントと同様のアカウントを使用して、ファイルを手動で開くことができます。何が問題なのかわからない。誰かが何が起こっているのか提案できますか?
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();
}
}
}