Table of Contents

Method InsertCrossReference

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

InsertCrossReference(WordDocument, DocumentPosition, CrossReferenceTarget, CrossReferenceKind, bool, FieldUpdateOptions?)

Inserts a cross-reference at a position, as one undoable edit: a REF, PAGEREF or NOTEREF field with its result, \h when it links, after putting Word's _Ref bookmark round a heading's text or a note's mark (one already there is reused).

public static DocumentEdit InsertCrossReference(this WordDocument document, DocumentPosition at, CrossReferenceTarget target, CrossReferenceKind kind, bool hyperlink = true, FieldUpdateOptions? options = null)

Parameters

document WordDocument

The document.

at DocumentPosition

Where the reference goes.

target CrossReferenceTarget

The heading, bookmark or note.

kind CrossReferenceKind

What it shows: text and above/below for a heading or bookmark, a number for a note, a page for any.

hyperlink bool

Whether a click on it goes to the target (\h). Defaults to true, as Word's dialog.

options FieldUpdateOptions

What PAGEREF shows (PageReference), or null to leave it to layout.

Returns

DocumentEdit

The edit; After is just past the reference.

Exceptions

ArgumentNullException

document or target is null.

ArgumentException

The position or the target is not in the document, the bookmark does not exist, the heading has no text, or the kind does not fit the target.

InvalidOperationException

The position is in a shape's text box or inside synthesized content.