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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:14:43+00:00 2026-05-18T03:14:43+00:00

I need to extract formatted text snippets of a Word document and store it

  • 0

I need to extract formatted text snippets of a Word document and store it inside an SQL Server table, for later processing and then reinsertion in the Word document using C#.

I’ve had a look at the Word DOM and it seems that I need to use a combination of the Document.Load(), Document.Save() and Range.Copy(), Range.Paste() methods to create a file for each snippets that I then load into the DB.

Isn’t there a easier (more efficient way)?

By the way the code snippets can be hidden text and I was thinking about storing the snippets as RTF.

  • 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-18T03:14:44+00:00Added an answer on May 18, 2026 at 3:14 am

    Finally I got to use Aspose.Words for .NET to extract the code snippets from the Word file I’m interested in and store them as RTF:

    // Get insteresting code snippets (in this case text runs with 
    // style "tw4winMark")
    Document sourceDocument = new Document(fileName);
    var runs = sourceDocument.GetChildNodes(NodeType.Run, true)
        .Select(r => r.Font.StyleName == "tw4winMark").ToList();
    
    // Store snippets into temporary document
    // Read Aspose documentation for details
    Document document = new Document();
    if (runs.Count > 0) {
        NodeImporter nodeImporter = new NodeImporter(
            runs[0].Document,
            document,
            ImportFormatMode.KeepSourceFormatting
        );
    
        foreach (Run run in runs) {
            Run importedRun = nodeImporter.ImportNode(run, true) as Run;
            importedRun.Font.Hidden = false;
            document.Sections[0].Body.Paragraphs[0].AppendChild(importedRun);
        }
    }
    
    // save temporary document in MemoryStream as RTF
    RtfSaveOptions saveOptions = new RtfSaveOptions();
    MemoryStream ms = new MemoryStream();
    document.Save(ms, saveOptions);
    
    // retrieve RTF from MemoryStream
    ms.Seek(0, SeekOrigin.Begin);
    StreamReader sr = new StreamReader(ms);
    string rtf = sr.ReadToEnd();
    

    One can then store the rtf into a text field of the database as usual and edit it in a RTF text control.

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

Sidebar

Related Questions

I have text files formatted as such: R156484COMP_004A7001_20100104_065119.txt I need to consistently extract the
I need to read an XML formatted document from a C program and extract
I need to use a regexp to extract bold text from rtf formatted text.
I need to extract the text between two HTML tags and store it in
I need to extract this text: Line 1 text. Line 2 text. Line 2
I need to extract pure text form a random web page at runtime, on
I need to extract certain data from a file, but this file is formatted
I need to extract a table of data on a collection of pages. I
I have a column on an SQL Server 2005 table called BIO - the
I need to extract string from a value of a cell in Oracle table.

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.