[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Services
    Events
    Commands
    Keyboard Shortcuts
    HTML Tag Support
   [Collapse]Examples
    [Expand]Files
    [Collapse]Text
      How to: Select Text Programmatically
      How to: Insert Text at the Cursor Position
      How to: Obtain the Document Position under the Mouse Pointer
      How To: Obtain Specific Document Part
      How to: Append Text to the Paragraph
      How to: Mark Text as Hidden and Display Hidden Text in the RichEditControl
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Document Elements
    [Expand]Layout
    [Expand]Automation
    [Expand]Search and Replace
    [Expand]Mail Merge
    [Expand]Spell Check
    [Expand]Export-Import
    [Expand]Printing
    [Expand]Protection
    [Expand]User Interface Customization
    [Expand]Commands
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How To: Obtain Specific Document Part

This example demonstrates how to retrieve the DocumentRange occupied by a specific document part.

You can use the following approaches to get a specific document part:

  • Section - Use the Section.Range property to access the required section's range. Refer to the How to obtain a specific section content repository for a code example.

  • Page - call the DocumentLayout.GetPage method to iterate through the document pages. The LayoutPage.MainContentRange property returns the obtained page's range as a FixedRange object. Call the SubDocument.CreateRange method to convert the retrieved FixedRange to DocumentRange.

  • Paragraphs with Headings (if Heading1, Heading2, etc. style is applied to the headings) – Applying the Heading style to the paragraph changes its outline level. Find all paragraphs with the required Paragraph.OutlineLevel property value. Then obtain the range located between these paragraphs (including the paragraph with the heading).

You can get text from the DocumentRange instance. The table below shows API used to retrieve and insert format-specific content:

Format Retrieve Insert
Plain Text SubDocument.GetText SubDocument.AppendText - Appends the specified text.
SubDocument.AppendSingleLineText - Appends text as a single line.
SubDocument.InsertText - Inserts the specified text at the specified position.
SubDocument.InsertSingleLineText - Inserts a single line of text (text without line breaks) at the specified position.
Rich Text Format SubDocument.GetRtfText SubDocument.AppendRtfText - Appends formatted text.
SubDocument.InsertRtfText - Inserts the specified formatted text into the specified position.
HTML SubDocument.GetHtmlText SubDocument.AppendHtmlText - Appends HTML formatted text.
SubDocument.InsertHtmlText - Inserts the specified HTML text into the specified position.
MHT SubDocument.GetMhtText
WordML SubDocument.GetWordMLText
OpenXML array SubDocument.GetOpenXmlBytes

Is this topic helpful?​​​​​​​