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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:33:20+00:00 2026-05-23T12:33:20+00:00

So I’ve created a C# library that manipulates and edits Word Documents. This of

  • 0

So I’ve created a C# library that manipulates and edits Word Documents. This of course references the OpenXML SDK. Where I use the library however I do not wan’t to have to reference the .dll as well.

One method that I might use from another project has a WordprocessingDocument parameter and has this profile:

public bool FillTemplate(ref WordprocessingDocument document, XElement data)
{
    //EDIT the document and return True if succesful.
}

problem here is of course that I would have to create a WordprocessingDocument inside the other project instead of just passing a stream.

Ok I guess the simplest solution would be a different profile on the method:

public bool FillTemplate(Stream document, XElement data)
{
    WordprocessingDocument doc = WordprocessingDocument.Open(document, true);
    return FillTemplate(doc, data);
}

But I got what I thought would be a brilliant idea just to create a extension method for Stream:

public static WordprocessingDocument ConvertToWordDocument(this Stream stream, bool isEditable)
{
    return WordprocessingDocument.Open(stream, isEditable);
}

and use it like this:

FileStream fStream = new FileStream(@"C:\Users\Me\Desktop\SomeDoc.docx", FileMode.Open);
var doc = fStream.ConvertToWordDocument(true);
filler.FillTemplate(ref doc, getXmlDataFor(42));

fStream.Flush();
fStream.Close();

However this doesn’t work for some reason (Doc changes but it doesn’t seem to get returned to the stream) and I got a little skeptical about the whole idea of how I’m using Streams and the WordprocessingDocument package/wrapper thingy.

What would be a optimal solution so I’m not going into a whole lot of trouble? How actually does the WordprocessingDocument class work in relation to passing it around as a parameter and such? Why didn’t the stream change the originally opened document?

  • 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-23T12:33:20+00:00Added an answer on May 23, 2026 at 12:33 pm
    System.IO.Packaging.Package
    

    seems to be the way to go when handling opc packages.
    Following lines of code looks fine to me. Package.Open have a number of constructors that you can use with path strings, streams etc…

    System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(@"C:\Users\Me\Desktop\SomeDoc.docx");
    DocumentFormat.OpenXml.Packaging.WordprocessingDocument document = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(package, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
    
    // edit document                
    package.Flush();
    package.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but

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.