Unplanned
Last Updated: 03 Apr 2018 10:19 by ADMIN
ADMIN
Boby
Created on: 03 Apr 2018 10:18
Category: WordsProcessing
Type: Feature Request
1
WordsProcessing: Provide API for editing properties of bookmarks, hyperlinks, and other supported fields
Currently there is no easy way to modify the properties of bookmarks and fields in the document. Think of providing API for easier manipulation.

For example, following is one of the easiest approached to change the target of hyperlinks:

                    var hyperlinkStarts = document
                        .EnumerateChildrenOfType<FieldCharacter>()
                        .Where(fc => fc.FieldCharacterType == FieldCharacterType.Start && fc.FieldInfo.Field is Hyperlink);

                    foreach (var fieldCharacter in hyperlinkStarts)
                    {
                        int indexOfCodeRun = fieldCharacter.Paragraph.Inlines.IndexOf(fieldCharacter) + 1;
                        Run hyperlinkCode = (Run)fieldCharacter.Paragraph.Inlines[indexOfCodeRun];

                        string oldUri = ((Hyperlink)fieldCharacter.FieldInfo.Field).Uri;
                        string newUri = "mailto:mail@mail.com";

                        hyperlinkCode.Text = hyperlinkCode.Text.Replace($"\"{oldUri}\"", $"\"{newUri}\"");
                        fieldCharacter.FieldInfo.UpdateField();
                    }
0 comments