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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:21:15+00:00 2026-06-09T19:21:15+00:00

I have a document that I am iterating thru getting the paragraphs. For each

  • 0

I have a document that I am iterating thru getting the paragraphs. For each of these paragraphs I need to create a new document and save it. I can’t figure out how to add a Paragraph from the source document to the new one.

        foreach (var p in paragraphsFromSourceDocument)
        {
            using (var memoryStream = new MemoryStream())
            {
                var doc = WordprocessingDocument.Create(memoryStream, WordprocessingDocumentType.Document);
                doc.AddMainDocumentPart();

                // Create the Document DOM. 
                doc.MainDocumentPart.Document = new Document();
                doc.MainDocumentPart.Document.Body = new Body();

                //Add the paragraph 'p' to the Body here:
                // HOW ?????????

                doc.MainDocumentPart.Document.Save();
            }
        }
  • 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-09T19:21:17+00:00Added an answer on June 9, 2026 at 7:21 pm
     // Open the file read-only since we don't need to change it.
            using (var wordprocessingDocument =  WordprocessingDocument.Open(documentFileName, true))
            {
                paragraphs = wordprocessingDocument.MainDocumentPart.Document.Body
                    .OfType<Paragraph>().ToList();
                styles = wordprocessingDocument.MainDocumentPart.StyleDefinitionsPart;
    
                foreach (var p in paragraphs)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        var doc = WordprocessingDocument.Create(memoryStream, WordprocessingDocumentType.Document);
                        doc.AddMainDocumentPart().AddPart(styles);
                        doc.MainDocumentPart.Document = new Document();
                        doc.MainDocumentPart.Document.Body = new Body();
                        doc.MainDocumentPart.Document.Body.Append(p.CloneNode(true));
                        doc.MainDocumentPart.Document.Save();
                        Console.WriteLine(GetHTMLOfDoc(doc));
    
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document that my asp.net page is creating and I need to
I have a word document that was saved as xml. now I need to
I am iterating over some elements and I have found that document.getElementById(id) works, but
I have an XML document coming in over a socket that I need to
I have a document that I want to be flipped / rotated 180 degrees
I have a document that looks something like <root> <element> <subelement1 /> <subelement2 />
I have a document that is an overview document within a folder, there are
I am working on Lotus Notes and I have a document that contains multiple
I have an XML document that I'm trying to search through. The Main structure
I have an aspx document that returns a list of incoming flights from a

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.