Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4251212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:37:52+00:00 2026-05-21T04:37:52+00:00

I am creating an application that gets thousands of word documents from an Oracle

  • 0

I am creating an application that gets thousands of word documents from an Oracle database and need to transform them into pdf and send them back to database. I already have all the support mechanism (database interaction, multitasking and a plugable approach to database and configuration) up and running. In spite of all warnings about using office automation in the server side my first approach was to use it (the truth is that my customer asked to use it). But I’m going mad with the interaction between c# (.Net 4.0) and word 2007. I already tried the SaveAs and the ExportAsFixedFormat. Both worked fine but when I try to close the word… I got an erro (pop up window saying that word found a problem and will be closed). Then I tried to include this before quitting the application:

wordApplication.NormalTemplate.Saved = true;

But it still throwing the errror. I’m unable to convert more than one hundred docs without an error. Do you know some way to achieve this conversion without using office automation? Or in the other hand, do you know how to do this conversion through office automation without errors? Any help will be very appreciated.

EDIT:
Otaku, here is an example of the code I am using (WARING! testing code ahead)

 if (wordApplication == null)
        {
            try
            {
                wordApplication = (ApplicationClass)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") ??
                             new ApplicationClass();
            }
            catch (COMException)
            {
                Type type = Type.GetTypeFromProgID("Word.Application");
                wordApplication = (ApplicationClass)System.Activator.CreateInstance(type);
            }

        }


        wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone;
        wordApplication.DisplayRecentFiles = false;
        wordApplication.Visible = false;
        wordApplication.ScreenUpdating = false;

        Document wordDocument = null;

        object paramSourceDocPath = Path.Combine(TempFolder, sourceFilename);
        var paramExportFilePath = Path.Combine(TempFolder, sourceFilename + ".pdf");
        var paramMissing = Type.Missing;

        const WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
        const bool paramOpenAfterExport = false;
        const WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
        const WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
        const int paramStartPage = 0;
        const int paramEndPage = 0;
        const WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
        const bool paramIncludeDocProps = true;
        const bool paramKeepIrm = true;
        const WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
        const bool paramDocStructureTags = true;
        const bool paramBitmapMissingFonts = true;
        const bool paramUseIso190051 = false;

        try
        {
            // Open the source document.
            wordDocument = wordApplication.Documents.Open(
                ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing, ref paramMissing, ref paramMissing,
                ref paramMissing);

            // Export it in the specified format.
            if (wordDocument != null)
            {

                //DocumentSaveAs(wordDocument);

                Logger.Write("Open document" + sourceFilename, "info");
                wordDocument.ExportAsFixedFormat(paramExportFilePath,
                                                 paramExportFormat, paramOpenAfterExport,
                                                 paramExportOptimizeFor, paramExportRange, paramStartPage,
                                                 paramEndPage, paramExportItem, paramIncludeDocProps,
                                                 paramKeepIrm, paramCreateBookmarks, paramDocStructureTags,
                                                 paramBitmapMissingFonts, paramUseIso190051,
                                                 ref paramMissing);
            }
        }
        catch (Exception ex)
        {
            Logger.Write(ex.Message);
            throw;
        }
        catch
        {
            Logger.Write("Empty catch.");
            throw;
        }
        finally
        {
            try
            {

            object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
            // Close and release the Document object.
            if (wordDocument != null)
            {

                wordDocument.Close(ref saveChanges, ref paramMissing,
                                   ref paramMissing);
                Thread.Sleep(2000);
                wordDocument = null;
            }

            // Quit Word and release the ApplicationClass object.

            foreach (Document document in wordApplication.Documents)
            {
                document.Close(saveChanges, paramMissing, paramMissing);
            }
            wordApplication.NormalTemplate.Saved = true;
            wordApplication.Quit(ref saveChanges, ref paramMissing,
                                 ref paramMissing);
            //Thread.Sleep(1000);
            wordApplication = null;


            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();


            Logger.Write("Deleting word file " + sourceFilename, "info");
            File.Delete(paramSourceDocPath.ToString());
            Logger.Write("File deleted " + sourceFilename, "info");

            Logger.Write("Reading pdf data " + paramExportFilePath, "info");
            ret = File.ReadAllBytes(paramExportFilePath);
            Logger.Write("Data read " + sourceFilename + ".pdf", "info");
            File.Delete(paramExportFilePath);
            Logger.Write("Pdf file deleted " + paramExportFilePath, "info");
            }
            catch (Exception e)
            {
                Logger.Write(e,"info");
                throw;
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:37:53+00:00Added an answer on May 21, 2026 at 4:37 am

    We use a commercial product called Aspose for all our Office integrations (as it does not actually require Office, is very fast, and is not Interop). I am not 100% sure if your exact scenario would be supported, but they have many samples on their website and if your project supports buying the couple licenses this can make your life a lot easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are creating an XBAP application that we need to have rounded corners in
I am creating a small application that will be deployed on Window. The database
I'm creating an installation script for an application that I'm developing and need to
I am creating a C# Windows Mobile application that I need to programmatically invoke
I'm working on an application that gets content from feeds in C#. This content
So, just like the title says, I need to create an application that gets
I'm creating a drawing application that renders OpenGL when it gets a WM_SCROLL or
I'm creating an android application that gets the current time in a different country/time-zone.
I'm creating an application that will store a hierarchical collection of items in an
I am creating an application that manages multiple instances of an external utility, supplying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.