Convert Microsoft PowerPoint Presentation to a Video Using C# .NET and Hosting Tips (IIS)

Development

We will need following References for the project

Microsoft.Office.Core;
Microsoft.Office.Interop.Graph;
System.Runtime.InteropServices;
Microsoft.Office.Interop.PowerPoint;
System.IO;

Method for the video conversion

public string makeVideo()
{
  string videoFilePath = "\videoName.wmv", presentationPath = "\yourPresentation.pptx";
  try
  {
    Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
    Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
    Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(
      presentationPath,
      MsoTriState.msoFalse,
      MsoTriState.msoFalse,
      MsoTriState.msoFalse);
    System.Threading.Thread.Sleep(180);
    oPres.UpdateLinks();
    try
    {
      oPres.UpdateLinks();

      //CreateVideo(string FileName, bool UseTimingsAndNarrations, int DefaultSlideDuration, int VertResolution, int FramesPerSecond, int Quality)
      oPres.CreateVideo(videoFilePath, true, 5, videoModel.size, 30, 85);

     while (oPres.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusInProgress || oPres.CreateVideoStatus == Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusQueued)
     {
        System.Threading.Thread.Sleep(10000);
     }
  return "Video is Created !!";
  }
  catch (Exception er)
  {
    string error = er.StackTrace.ToString();
    return error;
  }

  finally
  {
   oPres.Close();
   ppApp.Quit();
   GC.Collect();
  }
  }
  catch (Exception err)
  {
    string error2 = err.ToString();
    return error2;
  }
}

Now your PowerPoint presentation to video program is ready.

Hosting

When you host this in IIS there are few configurations to be done.  Otherwise you will get an error exception something like below.

System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} failed due to the following error: 80070005 Access is denied.

Followings are the configurations to avoid that error.

  1. Create a user in Admin group (i e: powerpointUser) (You can also use an existing user).
  2. set Password Never Expire and Password Cannot Be change for this user.
  3. Go to Control Panel  >> Administrative Tools >> Component Services >> Computers >> My Computer >> DCOM Config.
  4. Select Microsoft Word 97 – 2003 Document and right click and open Properties.
  5. In General tab set Authentication Level : None.
  6. In Security tab Customize all 3 permissions and add Everyone user by clicking the Edit button.
  7. In Identity tab select “This User” add details for the user created in first step. (powerpointUser).
  8.  Click Apply and Ok.
  9. Do the above 5,6,7,8 steps to the Microsoft PowerPoint Application and Microsoft PowerPoint Slide too in the DCOM Config.
  10. Host your website in the IIS and add the user created in first step (powerpointUser) to the website. (right click on the website in IIS and select “Edit Permissions…”. You can add the user in Security tab)

Now your program should work fine after hosting in IIS.