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

  • SEARCH
  • Home
  • 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 8109545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:27:16+00:00 2026-06-06T01:27:16+00:00

I had written a function to generate a word document by using the Office

  • 0

I had written a function to generate a word document by using the Office Interop Word object. My code is as shown below. It is working fine in my local system. But when i try to run it from window server 2003 it is not working. It keeps loading at Word.Document wordDoc = wordApp.Documents.Open and doesn’t do anything. Could you help me out?

private void GenerateEmploymentCertificate()
{
    object Nothing = System.Reflection.Missing.Value;
    object format = Word.WdSaveFormat.wdFormatDocument;
    Word.Application wordApp = new Word.ApplicationClass();

    object srcFileName = Server.MapPath(ResolveUrl(@"~/HRLetter\Arabia\Templates\Employment Certificate.doc"));
    Word.Document wordDoc = wordApp.Documents.Open
   (ref srcFileName, ref format, ref Nothing, ref Nothing,
   ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
   ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
   ref Nothing, ref Nothing);
    try
    {

        object bookmarkDate = "Date";
        wordDoc.Bookmarks.get_Item(ref bookmarkDate).Select();
        wordApp.Selection.Text = string.Format("{0:MM/dd/yyyy}", lblRequestdate.Text);

        object bookmarkEmployeeName = "EmployeeName";
        wordDoc.Bookmarks.get_Item(ref bookmarkEmployeeName).Select();
        wordApp.Selection.Text = lblEmployeeName1.Text;

        object bookmarkCompany = "Company";
        wordDoc.Bookmarks.get_Item(ref bookmarkCompany).Select();
        wordApp.Selection.Text = lblCompanyName1.Text; 

        object bookmarkJoiningDate = "JoiningDate";
        wordDoc.Bookmarks.get_Item(ref bookmarkJoiningDate).Select();
        wordApp.Selection.Text = string.Format("{0:MM/dd/yyyy}", lblJoiningDate1.Text); 

        object bookmarkDesignation = "Designation";
        wordDoc.Bookmarks.get_Item(ref bookmarkDesignation).Select();
        wordApp.Selection.Text = lblDesignation1.Text;

        string DocName;
        DocName = string.Format("{0}_employment_certificate", lblRequestNo.Text);
        hFilename.Value = DocName;
        wordDoc.SaveAs(Server.MapPath(ResolveUrl(@"~/HRLetter\Arabia\Letters\" + DocName + ".doc")));

    }
    catch (Exception exp)
    {
        Session["generalError"] = null;
        Session["generalError"] = "There was an error at generating the letter. Please send email to unify.admin@unilever.com with this screen shot.<br /><br /><br />Request No:" + lblRequestNo.Text + "<br />Action:Submit<br />" + exp.StackTrace.ToString();
        LogManager logHelper = new LogManager(Request.PhysicalApplicationPath.Trim(), "Leave System - Malaysia");
        logHelper.LogError("[btnSubmit_Click - ]" + exp.Message + ".StackTrace - " + exp.StackTrace.ToString());
        Response.Redirect(ResolveUrl("~/Error/ErrorHandler.aspx"));
    }
    finally
    {
        // Close wordDoc2
        wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
        if (wordDoc != null)
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc);
            wordDoc = null;
        }
        // close wordApp
        wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
        if (wordApp != null)
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
            wordApp = null;
        }
    }
    GC.Collect();}
  • 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-06-06T01:27:20+00:00Added an answer on June 6, 2026 at 1:27 am

    MS office doesn’t really work in server environment. Even MS says so.

    We’ve made it work with LibreOffice. You can read it on our blog

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

Sidebar

Related Questions

I was overlooking some code that I had written to generate an A-Z navigation
I had written this code out using Adobe CS3 and have recently upgraded to
I had the following idea: Say we have a webapp written using django which
My code base initially was written in ruby. It had a rakefile.rb file to
I had previously written a function that seems to work, but unfortunately I didn't
Background: I recently completed a tic-tac-toe game in AS3, using some simple function-based code
I had written C++ code for a problem. After that i have tried to
UPDATE!! I am sorry for this post, the code I had written for this
I have written a function using javascript for validating a Date selected from a
I want to validate my text are while entering data. I had written code

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.