Cross References and footnotes

I am using Aspose.Words for .Net and I am trying to insert a cross-reference to a footnote. (You do this so that you can reference a footnote multiple times, but only insert the footnote text once.) This is possible in MS Word, but I can’t quite figure out how to do it in Aspose.Words.

If it matters, in MS Word, the field looks like this: {NOTEREF _Ref185070032 \f} I just can’t figure out how to determine the magic number: _Ref185970032 from a previously inserted footnote.

Please help,

Adam

Hi
Thanks for your inquiry. This “magic number” is name of auto generated bookmark that is created surround footnote. This looks like the following.
BookmarkStart
Footnote
BookmarkEnd
You can try to achieve this using the following code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// write some text
builder.Write("Some text is added.");
// insert footnote
Footnote footnote = builder.InsertFootnote(FootnoteType.Footnote, "Footnote text.");
// create name
string name = String.Format("_Ref{0}",footnote.GetHashCode().ToString());
// create bookmark
BookmarkStart start = new BookmarkStart(doc, name);
BookmarkEnd end = new BookmarkEnd(doc, name);
// insert bookmark start before footnote
footnote.ParentParagraph.InsertBefore(start, footnote);
// insert bookmark end after footnote
footnote.ParentParagraph.InsertAfter(end, footnote);
// insert NOTEREF field (YOu should update this field in MS WORD)
builder.InsertField(String.Format(@"NOTEREF {0} \h", name), "1");
// save document
doc.Save(@"407_105812_ategen\out.doc");

But there in one problem. Aspose.Words doesn’t update NOTEREF fields. That’s why you should update an inserted field manually in MS Word.
I hope that this information will help you. Please let me know if you would like to know something else.
Best regards.

Thanks. That code does work as long as I update the fields manually in Word.

Are there any plans for Aspose.Words to update these fields? The whole reason for using my use of Aspose.Words was to avoid Word automation.

Thanks much,

Adam

Hi
Yes, we have plans to implement this. See FAQ for more information.
Best regards.

Would there be any way for me to hack in some code that would update noteref’s? Maybe if you could point me in the right direction I could see what I can do.

Hi
Thanks for your inquiry. As workaround you can use a macro to automatically update fields. See the following link for more information.
https://support.microsoft.com/en-us/topic/the-filename-field-does-not-automatically-update-when-you-open-a-document-in-word-de2bfb95-d990-1ced-a618-5ac0a2ec1be4
Also see the attached document and the following code.

// Open template that contains macro for updating fields
Document doc = new Document("in.doc");
// ……………………………………………………………………………………
// Build document, Insert fields
// ……………………………………………………………………………………
// Save document
doc.Save("out.doc");

I hope this could help.
Best regards.