You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Word VSTO插件中访问文档库属性:脱离SharePoint的检索

Word VSTO插件:脱离SharePoint获取文档库属性的可行方案

我正在开发一款从VB.NET迁移到C#的Word VSTO插件,核心需求是在Word环境内直接访问文档库属性,无需依赖SharePoint服务,哪怕文件已经不在SharePoint存储中也能获取——这些属性在Word的「文件→信息」面板中是可见的。

尝试过的无效/受限方案

在找到可行方法前,我试过以下几种常规途径,但都遇到了问题:

  • BuiltInDocumentProperties:完全无法获取目标文档库属性
  • CustomDocumentProperties:同样无法定位到目标属性
  • ContentTypeProperties:仅能正常读取Description、DocId和DocUrlId三个属性,调用其余属性时直接报错

成功解决方案

最终通过Word对象模型中的CustomXMLParts找到了突破口:定位到NamespaceUri为http://schemas.microsoft.com/office/2006/metadata/properties的自定义XML部件,就能从中提取到所有需要的文档库属性。

C#代码示例

using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;

public static string GetDocumentLibraryProperty(Document doc, string propertyName)
{
    foreach (CustomXMLPart part in doc.CustomXMLParts)
    {
        if (part.NamespaceURI == "http://schemas.microsoft.com/office/2006/metadata/properties")
        {
            try
            {
                var node = part.SelectSingleNode($"//*[local-name()='{propertyName}']");
                return node?.Text ?? string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }
    }
    return string.Empty;
}

内容的提问来源于stack exchange,提问作者Eliah Thommen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 06:54:54