This project has moved and is read-only. For the latest updates, please go here.

Insert word specific location, like bookmark

Sep 13, 2013 at 11:16 AM
hi ,all .

I want find word bookmark or content Control, then insert some text,
like
public static List<SdtElement> GetSdtElementsByTag(MainDocumentPart mainDocPart, string contentControl)
        {
            
            List<SdtElement> sdtElement = mainDocPart.Document.Descendants<SdtElement>()
                .Where(
                    element =>
                    element.SdtProperties.GetFirstChild<SdtAlias>() != null &&
                    element.SdtProperties.GetFirstChild<SdtAlias>().Val == contentControl).ToList();
            if (sdtElement.Count == 0) {
                sdtElement = GetSdtElementsByTag(mainDocPart.HeaderParts, contentControl);
            }
            return sdtElement;
        }
then replace text method:
public static void ReplaceContentControl(SdtElement sdtElement, string newText)
        {
            if (sdtElement != null)
            {
                sdtElement.Descendants<Text>().FirstOrDefault().Text = newText;
            }
        }
I want use docX create table and insert specific location (bookmarks), how do this?

thanks.