//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.Globalization;usingGrapeCity.Documents.Word;usingGrapeCity.Documents.Word.Fields; namespaceDsWordWeb.Demos{// This sample shows how to use the NOTEREF field options to add// and customize a reference to a footnote or endnote marked by a// bookmark elsewhere in the document. A companion PAGEREF field// targeting the same bookmark shows that WordLayout can resolve a// page number for a bookmark anchored to a footnote/endnote mark.publicclassNoteRefFieldOpts {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); // The names of the target bookmarks:conststringfnBmk = "fnBookmark";conststringenBmk = "enBookmark"; var p1 = doc.Body.AddParagraph("See the footnote"); p1.GetRange().Footnotes.Add("This is the footnote text.");// The bookmark must be placed on the paragraph that contains the// footnote's reference mark -- not on content inside the footnote's// own body -- for NOTEREF/PAGEREF to be able to resolve it: p1.GetRange().Bookmarks.Add(fnBmk); p1.GetRange().Runs.Add(" and the endnote"); p1.GetRange().Endnotes.Add("This is the endnote text."); p1.GetRange().Bookmarks.Add(enBmk); p1.GetRange().Runs.Add("."); // Add some pages:var rnd = Util.NewRandom();for (int i = 0; i < rnd.Next(20, 25); i++) { doc.Body.AddParagraph(Util.LoremIpsumPar()); } // NOTEREF to the footnote, formatted like its own reference mark:var noteRefFn = newNoteRefFieldOptions(doc, fnBmk) { Hyperlink = true, FormatAsReferenceMark = true }; doc.Body.AddParagraph("Footnote reference mark: ").AddComplexField(noteRefFn); // NOTEREF to the endnote, as a plain number instead of its (roman numeral) mark:var noteRefEn = newNoteRefFieldOptions(doc, enBmk) { Hyperlink = true, FormatAsReferenceMark = false }; doc.Body.AddParagraph("Endnote number: ").AddComplexField(noteRefEn); // A PAGEREF to the same footnote bookmark shows that WordLayout can// now resolve a page number for a bookmark anchored to a footnote mark:var pageRefFn = newPageRefFieldOptions(doc, fnBmk) { Hyperlink = true }; doc.Body.AddParagraph("The footnote is on page: ").AddComplexField(pageRefFn); // Update fields using a specific culture: doc.UpdateFields(newGrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") }); // Done:return doc; } }}