c# - 获取项目的内容类型列/元数据

标签 c# sharepoint-2007

如何获取 SharePoint 文档库中项目的内容类型列或元数据?

此链接提供了我不需要的文件属性 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.properties.aspx

我只想获取项目的内容类型列。 我试过这个字符串 strXML = oItem.Xml.ToString();但它给了我同样的垃圾。

最佳答案

您可以使用 ContentType SPListItem 的属性。如果您想要列表中的所有内容类型,您可以使用 ContentTypes SPList 的属性。获得内容类型引用后,您可以检查其 Fields属性以获取列。

列表项的内容类型:

SPContentType contentType = myListItem.ContentType;

foreach (SPField field in contentType)
{
    // Do your stuff with this column
}

列表的内容类型:

SPContentTypeCollection contentTypes = myList.ContentTypes;
List<object> values = new List<object>();
List<SPContentTypeId> blackList = new List<SPContentTypeId>()
{
    SPBuiltInContentTypeId.System,
    SPBuiltInContentTypeId.Item,
};

var goodContentTypes = contentTypes.Where(c => !blackList.Contains(c.Id));

foreach (SPContentType contentType in goodContentTypes)
{
    foreach (SPField field in contentType.Fields)
    {
        // Do your stuff with this column e.g. Get value from item
        values.Add(myListItem[field.InternalName]);
    }
}

关于c# - 获取项目的内容类型列/元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5197452/

相关文章:

用于隐藏 Sharepoint 文档列表中按钮的 JavaScript

sharepoint - 共享点列表中带有C#语法突出显示的自定义文本字段

c# - 使用 UdpClient 发送数据时访问被拒绝

C# 将 byte[] 编码到带有 "ref object"签名的 COM SAFEARRAY 参数

c# - 如何在同一方法中将调用方法的名称作为参数动态传递?

永久运行的 SharePoint 解决方案部署 - SharePoint 2007

c# - 使用枚举设置元素的可见性?

c# - 如何通过 LINQ 比较没有时间的 DateTime?

c# - 如何比较 Sharepoint 列表项值?

c# - 以编程方式将 ScriptManager 添加到页面?