KB Article T456958
Visible to All Users

ASPxRichEdit - How to get actual header's and footer's text content on the server side

Description:
Some scenarios with ASPxRichEdit require ability to obtain its actual text content on the server side during a callback or postback processing. By the actual content, the content of an opened document with user modifications is meant.

Answer:
The task of retrieving ASPxRichEdit main content can be resolved by using the SaveCopy method. For example:

C#
MemoryStream ms = new MemoryStream(); ASPxRichEdit1.SaveCopy(ms, DocumentFormat.PlainText); ms.Position = 0; string plainText = new StreamReader(ms).ReadToEnd();
Visual Basic
Dim ms As New MemoryStream() ASPxRichEdit1.SaveCopy(ms, DocumentFormat.PlainText) ms.Position = 0 Dim plainText As String = New StreamReader(ms).ReadToEnd()

However, this approach returns only the main content text without the text displayed in the document's header and footer. To access the text, displayed in these sections, it's necessary to get the document's stream by using the SaveCopy method and open it via RichEditDocumentServer:

C#
MemoryStream stream = new MemoryStream(); ASPxRichEdit1.SaveCopy(stream, DocumentFormat.OpenXml); RichEditDocumentServer server = new RichEditDocumentServer(); stream.Position = 0; server.LoadDocument(stream, DocumentFormat.OpenXml);
Visual Basic
Dim stream As New MemoryStream() ASPxRichEdit1.SaveCopy(stream, DocumentFormat.OpenXml) Dim server As New RichEditDocumentServer() stream.Position = 0 server.LoadDocument(stream, DocumentFormat.OpenXml)

Then, obtain the header and footer text from the RichEditDocumentServer's Document by using the following methods:
Section.BeginUpdateHeader Method
Section.BeginUpdateFooter Method
So, the code to obtain a document's header's modified content is:

C#
SubDocument docHead = server.Document.Sections[0].BeginUpdateHeader(); string textHead = docHead.GetText(docHead.Range); server.Document.Sections[0].EndUpdateHeader(docHead);
Visual Basic
Dim docHead As SubDocument = server.Document.Sections(0).BeginUpdateHeader() Dim textHead As String = docHead.GetText(docHead.Range) server.Document.Sections(0).EndUpdateHeader(docHead)

To obtain the footer, you can use the following code:

C#
SubDocument docFoot = server.Document.Sections[0].BeginUpdateFooter(); string textFoot = docFoot.GetText(docFoot.Range); server.Document.Sections[0].EndUpdateFooter(docFoot);
Visual Basic
Dim docFoot As SubDocument = server.Document.Sections(0).BeginUpdateFooter() Dim textFoot As String = docFoot.GetText(docFoot.Range) server.Document.Sections(0).EndUpdateFooter(docFoot)

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.