We need to set the "Data not stored with document" flag ("\d") when adding a Field to an existing Word document via Interop but can't figure how to do so.
This example works well in terms of inserting the image link but it stores the image within the document and not remotely (which we need).
if (doc.Bookmarks.Exists("TrackingPixel"))
{
object oBookMark = "TrackingPixel";
object newText = @"https://www.remotelocation.com/trackingpixel/secretcode";
Range rng = doc.Bookmarks.get_Item(ref oBookMark).Range;
rng.Select();
rng.Fields.Add(
Range: rng,
Type: WdFieldType.wdFieldIncludePicture,
Text: newText,
PreserveFormatting: true
);
}
Any held would be appreciated. Thanks.
There are a number of ways adding switches to field codes can be done.
In the case presented in the question, the switch can be added to the string passed to the
Textparameter:If this were an existing field code (the switch should be added after the fact) it's possible to assign new content to the string. For example:
FWIW when adding a field I often pass the entire field code in as a string (use only the
Textparameter) and leave out theTypeparameter. I'll also setPreserveFormattingtofalseunless I know I explicitly want that behavior. The first is a personal preference. For the second, the\* MergeFormatswitch can result in very odd behavior when a field code updates with other (formatted, string) content. I will use it, however, for linked tables.