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 9210897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:10:43+00:00 2026-06-18T01:10:43+00:00

I’m working on a MS word template generator, it works like this: User opens

  • 0

I’m working on a MS word template generator, it works like this:

User opens a webpage fill in some text boxes, marks some check boxes and then clicks on the button, word document opens (template I previously defined before with all the bookmarks needed), using what he inputted in the webpage, it’s all in the document and the fields and check boxes are marked as he marked, he only needs to print the document. It worked PERFECTLY on my PC

But when I tested it on the server, an error occurred:
enter image description here

My code:
I have included the reference (using Word = Microsoft.Office.Interop.Word;)

private void CreateWordDocument(int DepositNo)
        {
            Random RandomClass = new Random();
            int randomInt = RandomClass.Next();
            string templateName = "Form15Template.docx";
            string docFileName = "Form15_" + DepositNo.ToString() + "_" + randomInt.ToString() + ".docx";
            string destenation = "D:\\_Documents\\Form15\\";
            File.Copy(Server.MapPath(@"_Documents/" + templateName), destenation + docFileName, true); // 


            String POBox = "9769";
            String City = "الرياض"; 
            String PostalCode = "11423";
            String Address = "ص.ب " + POBox + " " + City + " " + PostalCode;

            // Modify Checkboxes variables in Doc to true if they have been checked

            if (RadioButtonListResult.SelectedValue.Equals("اجتاز"))
                A = true;
            if (RadioButtonListResult.SelectedValue.Equals("تعديل") || RadioButtonListResult.SelectedValue.Equals("لم يجتز"))
                B = true;
            if (CheckBoxAllElements.Checked)
                AllElements = true;
            if (CheckBoxElements.Checked)
                Elements = true;
            if (CheckBoxEdit.Checked)
                Edit = true;
            if (CheckBoxBoxPage.Checked)
                BoxPage = true;
            if (CheckBoxRequestArabic.Checked)
                RequestArabic = true;
            if (CheckBoxMultiInvention.Checked)
                MultiInvention = true;
            if (CheckBoxRecency.Checked)
                Recency = true;
            if (CheckBoxInventiveStep.Checked)
                InventiveStep = true;
            if (CheckBoxImplemented.Checked)
                Implemented = true;
            if (CheckBoxC.Checked)
                C = true;
            if (CheckBoxD.Checked)
                D = true;

            object bA = "A", bB = "B", bC = "C", bD = "D", bAllElements = "AllElements", bElements = "Elements",
                bRecency = "Recency", bInventiveStep = "InventiveStep", bImplemented = "Implemented",
                bApprove = "Approve", bEdit = "Edit", bBoxPage = "BoxPage", bRequestArabic = "RequestArabic",
                bMultiInvention = "MultiInvention", bObjection = "Objection", bMark = "Mark",
                bRejection = "Rejection";


            //Start Word and open template.
            Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
            object FileName = @"C:\Users\aalhammad\Documents\Visual Studio 2010\Projects\FormEditing\FormEditing\_Documents\Form15Template.docx";
            object oMissing = System.Reflection.Missing.Value;
            oDoc = oWord.Documents.Open(ref FileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            // ============================================== CheckBoxes ====================================================
            // Modifying CheckBoxes in Document

            oDoc.FormFields.get_Item(ref bA).CheckBox.Value = A;
            oDoc.FormFields.get_Item(ref bB).CheckBox.Value = B;
            oDoc.FormFields.get_Item(ref bC).CheckBox.Value = C;
            oDoc.FormFields.get_Item(ref bD).CheckBox.Value = D;
            oDoc.FormFields.get_Item(ref bAllElements).CheckBox.Value = AllElements;
            oDoc.FormFields.get_Item(ref bElements).CheckBox.Value = Elements;
            oDoc.FormFields.get_Item(ref bRecency).CheckBox.Value = Recency;
            oDoc.FormFields.get_Item(ref bInventiveStep).CheckBox.Value = InventiveStep;
            oDoc.FormFields.get_Item(ref bImplemented).CheckBox.Value = Implemented;
            oDoc.FormFields.get_Item(ref bApprove).CheckBox.Value = Approve;
            oDoc.FormFields.get_Item(ref bEdit).CheckBox.Value = Edit;
            oDoc.FormFields.get_Item(ref bBoxPage).CheckBox.Value = BoxPage;
            oDoc.FormFields.get_Item(ref bRequestArabic).CheckBox.Value = RequestArabic;
            oDoc.FormFields.get_Item(ref bMultiInvention).CheckBox.Value = MultiInvention;
            oDoc.FormFields.get_Item(ref bObjection).CheckBox.Value = Objection;
            oDoc.FormFields.get_Item(ref bMark).CheckBox.Value = Mark;
            oDoc.FormFields.get_Item(ref bRejection).CheckBox.Value = Rejection;


            // ============================================== BookMarks =====================================================

            String ApplicantName = "شركة الزيت العربية السعودية",
                AgentName = "مكتب سليمان العمار للمحاماة والاستشارات القانونية",
                AppDate = "13/01/2013",
                Title = "حماية خط تدفق رأس بئر‏ ونظام اختبار باستخدام وحدة تحكم في سرعة مضخة كهربائية مغمورة وصمام فاصل يستخدم عند الطوارئ";

            // find bookmark

            object oBookmark = "DepositNO"; // name of bookmark in doc
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = GetDepositNO(DepositNo);
            oBookmark = "AppDate";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = AppDate;
            oBookmark = "Title";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Title;
            oBookmark = "ApplicantName";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ApplicantName; 
            oBookmark = "AgentName";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = AgentName;
            oBookmark = "Address";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Address;
            oBookmark = "AgentName01";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = AgentName;
            oBookmark = "Times";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Times;
            oBookmark = "NumOfElements";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = NumOfElements;
            oBookmark = "txtElements";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtElements;
            oBookmark = "txtRecency";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtRecency;
            oBookmark = "txtInventiveStep";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtInventiveStep;
            oBookmark = "txtImplemented";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtImplemented;
            oBookmark = "ElementsC";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ElementsC;
            oBookmark = "ElementsD1";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ElementsD1;
            oBookmark = "ElementsD2";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ElementsD2;
            oBookmark = "txtBoxPage";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = txtBoxPage;
            oBookmark = "Fees";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = Fees;
            oBookmark = "DepositNO01";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = GetDepositNO01(DepositNo);
            oBookmark = "ExamTime";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ExamTime;
            oBookmark = "ExamTime01";
            oDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = ExamTime;
object saveFileName = "D:\\_Documents\\Form15\\" + "Form15 " + DepositNo.ToString() + "_" + randomInt.ToString() + ".docx";

            oDoc.SaveAs(ref saveFileName, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing);

Knowing that I was working on: Visual Studios C# 2010, and Microsoft .NET Framework 4.0
And on the server it’s: Visual Studio C# 2005, MS Framework 2.0

Any idea what might the problem be?

  • 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-18T01:10:44+00:00Added an answer on June 18, 2026 at 1:10 am

    The ad-hoc solution to your issue is to install Microsoft Word (make sure to select the .NET Programmability Support component during setup) and run the application at least once as the user that is running the Web application. This user needs to be an interactive user having a desktop.

    Note that Office needs to be installed if you want to automate it – the interop assemblies you probably deployed are just a wrapper and do not contain the actual code.

    However, keep in mind that non-interactive automation of Microsoft Office application is tricky and not officially supported by Microsoft. It requires a lot more code to make the thing reliable and stable than you will find in the automation samples in MSDN. Things like creating an interactive desktop, maintaining word instances or accounting for blocking popup messages all need to be explicitly implemented in your code.

    A much better alternative would be to create your documents using the Open XML SDK (Though one should be aware that the generation is not thread-safe in the current SDK version).

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.