Back to Devexpress

Section.BeginUpdateHeader(HeaderFooterType) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-section-dot-beginupdateheader-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-headerfootertype-x29.md

latest9.2 KB
Original Source

Section.BeginUpdateHeader(HeaderFooterType) Method

Starts editing the document’s header of the specified type.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
SubDocument BeginUpdateHeader(
    HeaderFooterType type
)
vb
Function BeginUpdateHeader(
    type As HeaderFooterType
) As SubDocument

Parameters

NameTypeDescription
typeHeaderFooterType

A HeaderFooterType enumeration value, representing the type of the header open for editing.

|

Returns

TypeDescription
SubDocument

A SubDocument instance representing the header being edited.

|

Remarks

Use the Section.BeginUpdateHeader - Section.EndUpdateHeader method pair to edit header content. If the document has no header as yet, this method creates a header of the specified type and opens it for editing.

You can use the Section.HasHeader method to determine whether the document already has a header.

Example

View Example

csharp
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
Document document = wordProcessor.Document;
    Section firstSection = document.Sections[0];

    // Check whether the document already has a header (the same header for all pages).
    if (!firstSection.HasHeader(HeaderFooterType.Primary))
    {
        //If not, create an empty header.
        SubDocument headerDocument = firstSection.BeginUpdateHeader();
        headerDocument.Paragraphs.Append();
        firstSection.EndUpdateHeader(headerDocument);
    }
}
vb
Using wordProcessor As New RichEditDocumentServer()
Dim document As Document = wordProcessor.Document
    Dim firstSection As Section = document.Sections(0)

    ' Check whether the document already has a header (the same header for all pages).
    If Not firstSection.HasHeader(HeaderFooterType.Primary) Then
        'If not, create an empty header.
        Dim headerDocument As SubDocument = firstSection.BeginUpdateHeader()
        headerDocument.Paragraphs.Append()
        firstSection.EndUpdateHeader(headerDocument)
    End If
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginUpdateHeader(HeaderFooterType) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

word-processing-merge-documents-with-different-headers-and-footers/CS/Helpers/SectionsMerger.cs#L29

csharp
SubDocument source = sourceSection.BeginUpdateHeader(headerFooterType);
SubDocument target = targetSection.BeginUpdateHeader(headerFooterType);

word-document-api-use-track-changes/CS/word-processing-document-api-track-changes/Program.cs#L37

csharp
//Reject all revisions in the firts page's header:
SubDocument header = documentProcessor.Document.Sections[0].BeginUpdateHeader(HeaderFooterType.First);
documentRevisions.RejectAll(header);

winforms-rich-edit-manage-tracked-changes/CS/XtraRichEdit_TrackChanges/Form1.cs#L48

csharp
//Reject all revisions in the firts page's header:
SubDocument header = richEditControl1.Document.Sections[0].BeginUpdateHeader(HeaderFooterType.First);
documentRevisions.RejectAll(header);

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/HeaderAndFooter.cs#L35

csharp
// Modify the header of the HeaderFooterType.First type.
SubDocument myHeader = firstSection.BeginUpdateHeader(HeaderFooterType.First);
DocumentRange range = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ");

winforms-richedit-iterate-through-all-sub-documents/CS/SubDocumentHelper.cs#L29

csharp
{
    SubDocument header = section.BeginUpdateHeader(headerFooterType);
    subDocumentProcessor(header);

word-processing-merge-documents-with-different-headers-and-footers/VB/Helpers/SectionsMerger.vb#L28

vb
If Not sourceSection.HasHeader(headerFooterType) Then Return
Dim source As SubDocument = sourceSection.BeginUpdateHeader(headerFooterType)
Dim target As SubDocument = targetSection.BeginUpdateHeader(headerFooterType)

word-document-api-use-track-changes/VB/word-processing-document-api-track-changes/Program.vb#L34

vb
'Reject all revisions in the firts page's header:
Dim header As SubDocument = documentProcessor.Document.Sections(0).BeginUpdateHeader(HeaderFooterType.First)
documentRevisions.RejectAll(header)

winforms-rich-edit-manage-tracked-changes/VB/XtraRichEdit_TrackChanges/Form1.vb#L40

vb
'Reject all revisions in the firts page's header:
Dim header As SubDocument = richEditControl1.Document.Sections(0).BeginUpdateHeader(HeaderFooterType.First)
documentRevisions.RejectAll(header)

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/HeaderAndFooter.vb#L31

vb
' Modify the header of the HeaderFooterType.First type.
Dim myHeader As DevExpress.XtraRichEdit.API.Native.SubDocument = firstSection.BeginUpdateHeader(DevExpress.XtraRichEdit.API.Native.HeaderFooterType.First)
Dim range As DevExpress.XtraRichEdit.API.Native.DocumentRange = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ")

winforms-richedit-iterate-through-all-sub-documents/VB/SubDocumentHelper.vb#L24

vb
If section.HasHeader(headerFooterType) Then
    Dim header As SubDocument = section.BeginUpdateHeader(headerFooterType)
    subDocumentProcessor(header)

See Also

HasHeader(HeaderFooterType)

EditPageFooterCommand

Section Interface

Section Members

DevExpress.XtraRichEdit.API.Native Namespace