Back to Devexpress

Section.BeginUpdateHeader() Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-section-2077e1a7.md

latest8.8 KB
Original Source

Section.BeginUpdateHeader() Method

Starts editing the primary header for the current section.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
SubDocument BeginUpdateHeader()
vb
Function BeginUpdateHeader As SubDocument

Returns

TypeDescription
SubDocument

A SubDocument instance that is the header being edited.

|

Remarks

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

You can use the Section.HasHeader property to determine whether the document already has a header which is the same for all pages (a header of the HeaderFooterType.Primary type).

Example

View Example

csharp
Document document = server.Document;
document.AppendSection();
Section firstSection = document.Sections[0];
// Modify the header of the HeaderFooterType.First type.
SubDocument myHeader = firstSection.BeginUpdateHeader(HeaderFooterType.First);
DocumentRange range = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ");
Field fld = myHeader.Fields.Create(range.End, "PAGE \\* ARABICDASH");
myHeader.Fields.Update();
firstSection.EndUpdateHeader(myHeader);
// Display the header of the HeaderFooterType.First type on the first page.
firstSection.DifferentFirstPage = true;
vb
Dim document As Document = server.Document
document.AppendSection()
Dim firstSection As Section = document.Sections(0)
' Modify the header of the HeaderFooterType.First type.
Dim myHeader As SubDocument = firstSection.BeginUpdateHeader(HeaderFooterType.First)
Dim range As DocumentRange = myHeader.InsertText(myHeader.CreatePosition(0), " PAGE NUMBER ")
Dim fld As Field = myHeader.Fields.Create(range.End, "PAGE \* ARABICDASH")
myHeader.Fields.Update()
firstSection.EndUpdateHeader(myHeader)
' Display the header of the HeaderFooterType.First type on the first page.
firstSection.DifferentFirstPage = True

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginUpdateHeader() 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.

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/HeaderAndFooterActions.cs#L17

csharp
// Create an empty header.
SubDocument newHeader = firstSection.BeginUpdateHeader();
firstSection.EndUpdateHeader(newHeader);

word-document-api-examples/CS/CodeExamples/HeaderAndFooterActions.cs#L25

csharp
// Create a header.
SubDocument newHeader = firstSection.BeginUpdateHeader();
newHeader.AppendText("Header");

word-document-api-insert-inline-pictures/CS/Program.cs#L39

csharp
string imageUri = "http://i.gyazo.com/798a2ed48a3535c6c8add0ea7a4fc4e6.png";
SubDocument docHeader = document.Sections[0].BeginUpdateHeader();
Shape headerImage = docHeader.Shapes.InsertPicture(docHeader.Range.End, DocumentImageSource.FromUri(imageUri, wordProcessor));

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

csharp
{
    SubDocument headerDocument = firstSection.BeginUpdateHeader();
    document.ChangeActiveDocument(headerDocument);

word-document-api-use-printablecomponentlink-to-print-document/CS/PrintingSystem/Form1.cs#L24

csharp
srv.BeginUpdate();
SubDocument _header = srv.Document.Sections[0].BeginUpdateHeader();
_header.Fields.Create(_header.Range.Start,"DATE \\@ \"dddd, MMMM dd, yyyy HH:mm:ss\" \\MERGEFORMAT");

word-document-api-examples/VB/CodeExamples/HeaderAndFooterActions.vb#L22

vb
' Create a header.
Dim newHeader As DevExpress.XtraRichEdit.API.Native.SubDocument = firstSection.BeginUpdateHeader()
newHeader.AppendText("Header")

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/HeaderAndFooterActions.vb#L14

vb
' Create an empty header.
Dim newHeader As SubDocument = firstSection.BeginUpdateHeader()
firstSection.EndUpdateHeader(newHeader)

word-document-api-insert-inline-pictures/VB/Program.vb#L32

vb
Dim imageUri As String = "http://i.gyazo.com/798a2ed48a3535c6c8add0ea7a4fc4e6.png"
Dim docHeader As SubDocument = document.Sections(0).BeginUpdateHeader()
Dim headerImage As Shape = docHeader.Shapes.InsertPicture(docHeader.Range.End, DocumentImageSource.FromUri(imageUri, wordProcessor))

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

vb
If Not firstSection.HasHeader(DevExpress.XtraRichEdit.API.Native.HeaderFooterType.Primary) Then
    Dim headerDocument As DevExpress.XtraRichEdit.API.Native.SubDocument = firstSection.BeginUpdateHeader()
    document.ChangeActiveDocument(headerDocument)

word-document-api-use-printablecomponentlink-to-print-document/VB/PrintingSystem/Form1.vb#L24

vb
srv.BeginUpdate()
Dim _header As SubDocument = srv.Document.Sections(0).BeginUpdateHeader()
_header.Fields.Create(_header.Range.Start, "DATE \@ ""dddd, MMMM dd, yyyy HH:mm:ss"" \MERGEFORMAT")

See Also

HasHeader(HeaderFooterType)

EditPageHeaderCommand

Section Interface

Section Members

DevExpress.XtraRichEdit.API.Native Namespace