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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:00:52+00:00 2026-06-18T08:00:52+00:00

After struggling to get my word document to act right on my local machine,

  • 0

After struggling to get my word document to act right on my local machine, I understand my server does not have Microsoft Office. I am trying to open, modify, save and display a document. I figured out the OPEN XML SDK 2.0 is the way to go. I just download this program this morning and I don’t know how to integrate this in my code. How do I go about doing this?

I am flying blind, this is what I would like to do. This code works with office

object pathToUse = Server.MapPath("~/Document/TemplateX.docx");
object pathToSave = Server.MapPath("~/Document/FinishedX.docx");

//open file
tempDoc = wordApp.Documents.Open(ref pathToUse, ref missing,
   ref missing, ref missing, ref missing, ref missing,
   ref missing, ref missing, ref missing, ref missing,
   ref missing, ref isVisible, ref missing, ref missing,
   ref missing, ref missing);

//Make edits - I had this for my word document
this.FindAndReplace(Application wordApp, "<date>", DateTime.Today.ToShortDateString());

//save
tempDoc.SaveAs(ref pathToSave, ref missing,
   ref missing, ref missing, ref missing, ref missing,
   ref missing, ref missing, ref missing, ref missing,
   ref missing, ref isVisible, ref missing, ref missing,
   ref missing, ref missing);

//return file in my Controller
return File(pathToSave.ToString(), "docx");

I just added code to show I had what was needed but the lack of Microsoft curve ball hurt my mental roll. Thanks in advance. HELP!

  • 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-18T08:00:53+00:00Added an answer on June 18, 2026 at 8:00 am

    OpenXml SDK will let you do that but you may need to take into account special cases that can emerge from editing your template in Word, for example identically styled text being split into more than one elements.

    First go and download the Open XML addin for VS2010. It will let you see the structure you’re working with – drag a .docx file in VS2010, look for document.xml inside the package, press Ctrl-K-D to format the document for readability.

    Add the DLL(s) that come with the SDK to your project.

    Open the Word document from a stream, make sure to copy the template file before that:

    using (var document = WordprocessingDocument.Open(stream, true))
                    {
    ...
    }// document auto-saves when done
    

    Replace text inside tags:

    List<Text> textElements = document.MainDocumentPart.Document.Body.Descendants<Text>()
        .Where(t=>t.InnerText == "<date>").ToList();
    textElements.ForEach(te=>te.InnerText = DateTime.Today.ToShortDateString());
    

    This sample will get you started but expect to see Word structuring its XML in weird ways you didn’t expect, especially if your documents are complex.

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

Sidebar

Related Questions

OK so after struggling for a while trying to get cURL to fetch a
After some struggling I managed to get boost smart pointers to build for Windows
After deploying WCF server (svc) on my Server, I have got this message when
I'm struggling to redirect a user after their login request to the server is
I'm struggling to get a hang of branching in CVS after reading the documentation
I have a JSfiddle here: http://jsfiddle.net/mW9XD/ I'm struggling to get the amount of hours
I'm struggling with the right type of conditional select statement here, even after searching.
I am trying to understand pointers and arrays. After struggling to find pointers online(pun!),
I'm struggling to get some results from my database. I have a table like
After much struggling, i have come to a design dead end :( seeing as

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.