The Problem (Q-score 5, ranked #52nd of 95 in the VBA Core archive)
The scenario as originally posted in 2010
I have a ASP.NET 2.0 web application that should upload a ppt file and then extract its slides to images. For that I have imported office.dll and Microsoft.Office.Interop.PowerPoint.dll assemblies and wrote the following code
public static int ExtractImages(string ppt, string targetPath, int width, int height)
{
var pptApplication = new ApplicationClass();
var pptPresentation = pptApplication.Presentations.Open(ppt, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
var slides = new List<string>();
for (var i = 1; i <= pptPresentation.Slides.Count; i++)
{
var target = string.Format(targetPath, i);
pptPresentation.Slides[i].Export(target, "jpg", width, height);
slides.Add(new FileInfo(target).Name);
}
pptPresentation.Close();
return slides.Count;
}
If I run this code in my local machine, in asp.net or a executable, it runs perfectly. But If I try running it in the production server, I get the following error:
System.Runtime.InteropServices.COMException (0x80004005): PowerPoint
could not open the file. at
Microsoft.Office.Interop.PowerPoint.Presentations.Open(String
FileName, MsoTriState ReadOnly, MsoTriState Untitled, MsoTriState
WithWindow) at PPTImageExtractor.PptConversor.ExtractImages(String
caminhoPpt, String caminhoDestino, Int32 largura, Int32 altura, String
caminhoThumbs, Int32 larguraThumb, Int32 alturaThumb, Boolean geraXml)
at Upload.ProcessRequest(HttpContext context)
The process is running with the user NT AUTHORITYNETWORK SERVICE. IIS is configured to use anonymous authentication. The anonymous user is an administrator, I set it like this to allow the application to run without having to worry about permissions.
In my development machine I have office 2010 beta1. I have tested with the executable in a pc with office 2007 as well. And if I run the code from the executable in the server, with office 2003 installed, it runs perfectly.
To ensure that there wouldn’t be any problems with permissions, everyone in the server has full access to the web site. The website is running in IIS7 and Classic Mode.
I also heard that Open-office has an API that should be able to do this, but I couldn’t find anything about it. I don’t mind using DLLImport to do what I have to do and I can install open-office on the web server. Don’t worry about rewriting this method, as long as the parameters are the same, everything will work.
I appreciate your help.
Why community consensus is tight on this one
Across 95 VBA Core entries in the archive, the accepted answer here holds solid answer (above median) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — solid answer (above median) (+10)
Advisory answer — community consensus with reference links
Note: the verified answer below is a reference / advisory response rather than a copy-ready snippet.
Don’t ever use Office Interop from an ASP.NET application. See Considerations for server-side Automation of Office.
However, if you have no alternative, on Windows Server 2008 you need to create the following directories to get this to work:
Windows 2008 Server x64: C:WindowsSysWOW64configsystemprofileDesktop
Windows 2008 Server x86: C:WindowsSystem32configsystemprofileDesktop
When to Use It — vintage (14+ years old, pre-2013)
Ranked #52nd in its category — specialized fit
This pattern sits in the 92% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.
What changed between 2010 and 2026
The answer is 16 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.