2

I know this would be a duplicate question. I tried all the ways suggested in multiple websites, but my issue didn't get solved. I am getting the below error

System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at

Application appWord = new Application();
wordDocument = appWord.Documents.Open(strFilePath);
wordDocument.ExportAsFixedFormat(pdfPath, WdExportFormat.wdExportFormatPDF);
appWord.Quit();

Same solution working fine in Local, but in in server its giving the above error. I have added 'Network Service' user to 'Microsoft Word 97 - 2003 Document'and given all the permissions, Do these changes required server reboot?, and created desktop folders as well and I have MS word 2016 installed on web server. Thanks in advance.

Learner
  • 139
  • 1
  • 9
  • You say it's not working in a server environment, how is it deployed? Is this being run as a windows service or otherwise unattended? – DiskJunky Mar 26 '18 at 21:00
  • 1
    My app is running on windows 2012 and iis 8. – Learner Mar 26 '18 at 21:04
  • Ah. In that case, you'll need to give the application pool that the website runs under a Windows account (or domain account) and give it explicit access to the Office folders. A default IIS account is very limited in what it can do - one of many restrictions is not being able to access anything outside of the application's root folder. – DiskJunky Mar 26 '18 at 21:18
  • My app is running under 'Network Service' account and I gave it explicit access to the Office folders already, but still getting the same error. – Learner Mar 27 '18 at 08:24
  • If it's using the default IIS settings, then it's actually running under IIS's application pool account, `IIS APPPOOL\`. This is a local hidden group on the machine. Applications by default do *not* run under Network Service - this account is for running Windows Services that require network access. Can you confirm the account that the *application pool* is running under? – DiskJunky Mar 27 '18 at 08:36
  • To be clear, we are talking about a website application deployed onto IIS, not a desktop applicatoin/windows service? – DiskJunky Mar 27 '18 at 08:45
  • I have checked in Application Pools against my application and found 'NetworkService' under Identity option. Yes, Its a Web app deployed onto IIS. – Learner Mar 27 '18 at 08:49
  • The fact that it's running as `Network Service` is itself an issue as that account has very limited access to the machine, including `Program Files` directories. You can read the distinction here; https://stackoverflow.com/questions/510170/the-difference-between-the-local-system-account-and-the-network-service-acco. To resolve your issue, I'd recommend using a default application pool account and configure that account to have read/execute privileges on the installed `Office` folder. That should allow your application to access what it needs to – DiskJunky Mar 27 '18 at 10:01

0 Answers0