ContentRange Class
Represents a contiguous area in a document between two ContentPositions.
- Inheritance:
- System.ObjectContentRange
Remarks
ContentRange is defined by a starting and ending ContentPosition.
Similar to the way Bookmarks are used in a document, ContentRange instances are used to identify specific portions of a document. However, unlike a Bookmark, a ContentRange instance only exists while the programming code that defined it is running.
ContentPosition enables to view the document as a contiguous sequence of characters by hiding the complexity of the underlying hierarchical content model.
ContentRange offers following functionalities:
- Delete part of the document content with Delete() method.
- Set new content to a part of the document content with LoadText(String) and Set(ContentRange) methods.
- Insert new content before or after a part of the document content with Start.InsertRange(ContentRange) (or Start.LoadText(String)) and Start.InsertRange(ContentRange) (or End.LoadText(String)) methods.
- Find or replace all parts of the document content which match the specified string or specified System.Text.RegularExpressions.Regex with Find(String) or Replace(String, String) methods.
- Export part of the document content to a textual format with ToString() method.
ContentRange is exposed on following members:
- Content property so that all Element-derived classes from GemBox.Document Content Model have it.
- Content property so that all collection properties from GemBox.Document Content Model have it (for example, Blocks or Inlines).
- GetContent(Boolean) method so that bookmarked content can be set, deleted, searched etc.
For more information, see content manipulation examples.
Constructors
ContentRange(ContentPosition, ContentPosition)
Initializes a new instance of the ContentRange class.
public ContentRange(ContentPosition start, ContentPosition end)
Public Sub New(start As ContentPosition, end As ContentPosition)
Parameters
start
- ContentPosition
The ContentPosition that marks the beginning of the new ContentRange.
The ContentPosition that marks the end of the new ContentRange.
Exceptions
- System.ArgumentNullException
Argument start
or end
is null.
- System.ArgumentException
Arguments start
and end
do not belong to the same document.
Properties
End
Gets the ContentPosition that marks the end of the current ContentRange.
Property Value
The ContentPosition that marks the end of the current ContentRange.
FormFieldsData
Gets the snapshot of form fields data for all form fields in the current range.
public FormFieldDataCollection FormFieldsData { get; }
Public ReadOnly Property FormFieldsData As FormFieldDataCollection
Property Value
The snapshot of form fields data for all form fields in the current range.
Remarks
This property returns a snapshot of form fields data for all form fields in the current range at the particular time when this property is first time accessed. If current range is later expanded with additional form fields, they won't be contained in this property. To obtain latest snapshot, access Content again and use its FormFieldsData property.
Start
Gets the ContentPosition that marks the beginning of the current ContentRange.
Property Value
The ContentPosition that marks the beginning of the current ContentRange.
Methods
CountWords()
Counts the number of words in this content range.
Returns
- System.Int32
The number of words in this content range.
Delete()
Deletes the document content specified with the current ContentRange.
Remarks
For more information, see Delete Content example.
Find(String)
Finds all ContentRanges which contain the specified text.
public IEnumerable<ContentRange> Find(string text)
Public Function Find(text As String) As IEnumerable(Of ContentRange)
Parameters
text
- System.String
The text which should be searched for.
Returns
- System.Collections.Generic.IEnumerable<ContentRange>
All ContentRanges which contain the specified text.
Remarks
For more information, see Find and Replace example.
Exceptions
- System.ArgumentException
Argument text can't be null or empty.
Find(Regex)
Finds all ContentRanges which match the specified System.Text.RegularExpressions.Regex.
public IEnumerable<ContentRange> Find(Regex regex)
Public Function Find(regex As Regex) As IEnumerable(Of ContentRange)
Parameters
regex
- System.Text.RegularExpressions.Regex
The System.Text.RegularExpressions.Regex which should be matched.
Returns
- System.Collections.Generic.IEnumerable<ContentRange>
All ContentRanges which match the specified System.Text.RegularExpressions.Regex.
Remarks
For more information, see Find and Replace example.
GetChildElements()
Gets the child elements.
public IEnumerable<Element> GetChildElements()
Public Function GetChildElements As IEnumerable(Of Element)
Returns
- System.Collections.Generic.IEnumerable<Element>
Sequence of child elements.
Remarks
Method returns range child elements. Note that resulting enumeration will include range starting and ending element if not filtered.
GetChildElements(ElementType[])
Gets the child elements filtered by ElementType.
public IEnumerable<Element> GetChildElements(params ElementType[] filterElements)
Public Function GetChildElements(ParamArray filterElements As ElementType()) As IEnumerable(Of Element)
Parameters
filterElements
- ElementType[]
The ElementTypes to filter by.
Returns
- System.Collections.Generic.IEnumerable<Element>
Sequence of child elements filtered by ElementType.
Remarks
Method returns range child elements filtered by ElementType. Note that resulting enumeration will include range starting and ending element if not filtered.
LoadText(String)
Loads the specified text
to the current ContentRange.
public ContentRange LoadText(string text)
Public Function LoadText(text As String) As ContentRange
Parameters
text
- System.String
The text which should be loaded to the current ContentRange.
Returns
A ContentRange instance which contains loaded text.
Remarks
A load operation replaces the current ContentRange's content with the newly loaded content.
For more information, see Set Content example.
LoadText(String, CharacterFormat)
Loads the specified text
with specific formatting to the current ContentRange.
public ContentRange LoadText(string text, CharacterFormat format)
Public Function LoadText(text As String, format As CharacterFormat) As ContentRange
Parameters
text
- System.String
The text which should be loaded to the current ContentRange.
format
- CharacterFormat
The formatting of the text which should be be loaded to the current ContentRange.
Returns
A ContentRange instance which contains loaded text.
Remarks
A load operation replaces the current ContentRange's content with the newly loaded content.
For more information, see Set Content example.
LoadText(String, HtmlLoadOptions)
Loads the specified HTML text to the current ContentRange.
public ContentRange LoadText(string html, HtmlLoadOptions options)
Public Function LoadText(html As String, options As HtmlLoadOptions) As ContentRange
Parameters
html
- System.String
The HTML text which should be loaded to the current ContentRange.
options
- HtmlLoadOptions
The options used to define settings for load operation.
Returns
A ContentRange instance which contains loaded HTML text.
Remarks
A load operation replaces the current ContentRange's content with the newly loaded content.
For more information, see Word Editor in ASP.NET and Set Content example.
LoadText(String, RtfLoadOptions)
Loads the specified RTF text to the current ContentRange.
public ContentRange LoadText(string text, RtfLoadOptions options)
Public Function LoadText(text As String, options As RtfLoadOptions) As ContentRange
Parameters
text
- System.String
The RTF text which should be loaded to the current ContentRange.
options
- RtfLoadOptions
The options used to define settings for load operation.
Returns
A ContentRange instance which contains loaded RTF text.
LoadText(String, TxtLoadOptions)
Loads the specified text
to the current ContentRange.
public ContentRange LoadText(string text, TxtLoadOptions options)
Public Function LoadText(text As String, options As TxtLoadOptions) As ContentRange
Parameters
text
- System.String
The text which should be loaded to the current ContentRange.
options
- TxtLoadOptions
The options used to define settings for load operation.
Returns
A ContentRange instance which contains loaded text.
Remarks
A load operation replaces the current ContentRange's content with the newly loaded content.
For more information, see Set Content example.
Replace(String, String)
Replaces all occurrences of the specified text with another text in the current ContentRange.
[ComVisible(true)]
public void Replace(string oldValue, string newValue)
<ComVisible(True)>
Public Sub Replace(oldValue As String, newValue As String)
Parameters
oldValue
- System.String
The text which should be searched for.
newValue
- System.String
The text which should replace all occurrences of searched text.
Remarks
For more information, see Find and Replace example.
Replace(String, String, CharacterFormat)
Replaces all occurrences of the specified text with another text in the current ContentRange.
[ComVisible(false)]
public void Replace(string oldValue, string newValue, CharacterFormat format)
<ComVisible(False)>
Public Sub Replace(oldValue As String, newValue As String, format As CharacterFormat)
Parameters
oldValue
- System.String
The text which should be searched for.
newValue
- System.String
The text which should replace all occurrences of searched text.
format
- CharacterFormat
The formatting of the replacement text.
Remarks
For more information, see Find and Replace example.
Replace(Regex, ContentRangeEvaluator)
Replaces all ContentRanges which match the specified System.Text.RegularExpressions.Regex with ContentRange returned by a ContentRangeEvaluator delegate.
[ComVisible(false)]
public void Replace(Regex regex, ContentRangeEvaluator evaluator)
<ComVisible(False)>
Public Sub Replace(regex As Regex, evaluator As ContentRangeEvaluator)
Parameters
regex
- System.Text.RegularExpressions.Regex
The Regex which should be matched.
evaluator
- ContentRangeEvaluator
Custom method that examines each matched ContentRange and returns replacement ContentRange.
Remarks
For more information, see Find and Replace example.
Replace(Regex, String)
Replaces all matches of the specified System.Text.RegularExpressions.Regex with specified text in the current ContentRange.
[ComVisible(false)]
public void Replace(Regex regex, string replacement)
<ComVisible(False)>
Public Sub Replace(regex As Regex, replacement As String)
Parameters
regex
- System.Text.RegularExpressions.Regex
The Regex which should be matched.
replacement
- System.String
The text which should replace all matches of searched System.Text.RegularExpressions.Regex.
Remarks
For more information, see Find and Replace example.
Replace(Regex, String, CharacterFormat)
Replaces all matches of the specified System.Text.RegularExpressions.Regex with specified text in the current ContentRange.
[ComVisible(false)]
public void Replace(Regex regex, string replacement, CharacterFormat format)
<ComVisible(False)>
Public Sub Replace(regex As Regex, replacement As String, format As CharacterFormat)
Parameters
regex
- System.Text.RegularExpressions.Regex
The Regex which should be matched.
replacement
- System.String
The text which should replace all matches of searched System.Text.RegularExpressions.Regex.
format
- CharacterFormat
The formatting of the replacement text.
Remarks
For more information, see Find and Replace example.
SaveToClipboard(SaveOptions[])
Saves the current ContentRange to the clipboard using specified text formats.
public void SaveToClipboard(params SaveOptions[] listOfOptions)
Public Sub SaveToClipboard(ParamArray listOfOptions As SaveOptions())
Parameters
listOfOptions
- SaveOptions[]
List of SaveOptions type derivations mapping clipboard text formats.
Remarks
Applications which save data to clipboard should try to save it in all formats supporting that specific data.
Following SaveOptions type derivations can be used: RtfSaveOptions, HtmlSaveOptions and TxtSaveOptions. If no SaveOptions is specified, ContentRange is saved using all supported SaveOptions type derivations.
Exceptions
- System.ArgumentException
SaveOptions type derivation supplied inside listOfOptions
is not supported for this operation. Use one of the supported derivations: RtfSaveOptions, HtmlSaveOptions and TxtSaveOptions
SaveToClipboard(IEnumerable<SaveOptions>)
Saves the current ContentRange to the clipboard using specified text formats.
public void SaveToClipboard(IEnumerable<SaveOptions> listOfOptions)
Public Sub SaveToClipboard(listOfOptions As IEnumerable(Of SaveOptions))
Parameters
listOfOptions
- System.Collections.Generic.IEnumerable<SaveOptions>
List of SaveOptions type derivations mapping clipboard text formats.
Remarks
Applications which save data to clipboard should try to save it in all formats supporting that specific data.
Following SaveOptions type derivations can be used: RtfSaveOptions, HtmlSaveOptions and TxtSaveOptions.
Exceptions
- System.ArgumentException
SaveOptions type derivation supplied inside listOfOptions
is not supported for this operation. Use one of the supported derivations: RtfSaveOptions, HtmlSaveOptions and TxtSaveOptions
Set(ContentRange)
Sets the content of the current ContentRange to a content specified with the range
parameter.
public ContentRange Set(ContentRange range)
Public Function Set(range As ContentRange) As ContentRange
Parameters
range
- ContentRange
The ContentRange which specifies content which should be set to the current ContentRange.
Returns
A ContentRange instance which contains set content.
Remarks
For more information, see Set Content example.
ToString()
Returns a plain text that represents this ContentRange instance.
Returns
- System.String
A plain text that represents this ContentRange instance.
Overrides
Remarks
For more information, see Get Content example.