Office Interop Word error with SharePoint 2013

SaMuTa 0 Reputation points
2023-05-07T08:09:18.9833333+00:00

I developed a webpart that creates a Word document and exports it to PDF format using ExportAsFixedFormat. It worked in my development Sharepoint server. When I deployed it to the production server, I'm getting this error:

[COMException (0x80004005): Word has encountered a problem.] Microsoft.Office.Interop.Word.DocumentClass.ExportAsFixedFormat(String OutputFileName, WdExportFormat ExportFormat, Boolean OpenAfterExport, WdExportOptimizeFor OptimizeFor, WdExportRange Range, Int32 From, Int32 To, WdExportItem Item, Boolean IncludeDocProps, Boolean KeepIRM, WdExportCreateBookmarks CreateBookmarks, Boolean DocStructureTags, Boolean BitmapMissingFonts, Boolean UseISO19005_1, Object& FixedFormatExtClassPtr) +0test.PdfExporter.WebParts.PrintPDF.<>c__DisplayClass4_0.b__0() +10785Microsoft.SharePoint.<>c__DisplayClass5.b__3() +349Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) +197Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) +423Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) +95test.PdfExporter.WebParts.PrintPDF.PrintPDFUserControl.generateWodDoc(ServiceConfermationList serviceConfermationList) +158test.PdfExporter.WebParts.PrintPDF.PrintPDFUserControl.<btnPrint_Click>b__3_0() +2075Microsoft.SharePoint.<>c__DisplayClass5.b__3() +349Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) +197Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) +423Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) +95test.PdfExporter.WebParts.PrintPDF.PrintPDFUserControl.btnPrint_Click(Object sender, EventArgs e) +94System.Web.UI.WebControls.Button.OnClick(EventArgs e) +99System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2749

This is an example of the code used:

using Microsoft.Office.Interop.Word;

// Create a new Word application
Application wordApp = new Application();

// Create a new document
Document doc = wordApp.Documents.Add();

// Insert content into the document
Paragraph para = doc.Content.Paragraphs.Add();
para.Range.Text = "Hello, World!";

// Export the document as PDF
string pdfFileName = "example.pdf";
doc.ExportAsFixedFormat(pdfFileName, WdExportFormat.wdExportFormatPDF);

// Clean up
doc.Close();
wordApp.Quit();

Notes:

  1. I used the C:\inetpub\wwwroot\wss\VirtualDirectories\ path as the destination for the saved file
  2. I use Office 2013.

Can you help me solve the issue that I got?

Word
Word
A family of Microsoft word processing software products for creating web, email, and print documents.
714 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,645 questions
0 comments No comments
{count} votes