AddLinkToContent

CustomDocumentProperties.AddLinkToContent method

创建一个新的链接到内容自定义文档属性。

public DocumentProperty AddLinkToContent(string name, string linkSource)
范围类型描述
nameString属性的名称。
linkSourceString财产来源。

返回值

新创建的属性对象或无效的当。。。的时候linkSource是无效的。

例子

演示如何将自定义文档属性链接到书签。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartBookmark("MyBookmark");
builder.Write("Hello world!");
builder.EndBookmark("MyBookmark");

// 将新的自定义属性链接到书签。该房产的价值
// 将是它在“LinkSource”成员中引用的书签的内容。
CustomDocumentProperties customProperties = doc.CustomDocumentProperties;
DocumentProperty customProperty = customProperties.AddLinkToContent("Bookmark", "MyBookmark");

Assert.AreEqual(true, customProperty.IsLinkToContent);
Assert.AreEqual("MyBookmark", customProperty.LinkSource);
Assert.AreEqual("Hello world!", customProperty.Value);

doc.Save(ArtifactsDir + "DocumentProperties.LinkCustomDocumentPropertiesToBookmark.docx");

也可以看看