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

发布于 2024-10-20 12:10:13 字数 337 浏览 5 评论 0原文

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

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

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

How to get content type columns or metadata for an item in SharePoint document library?

This links gives the file properties that i don't need
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.properties.aspx

I only to want to get content type columns for an item.
I tried this string strXML = oItem.Xml.ToString(); but it gives me same garbage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

っ〆星空下的拥抱 2024-10-27 12:10:13

您可以使用 < SPListItem 的 code>ContentType 属性。如果您希望列表中的所有内容类型,可以使用 SPListContentTypes 属性。获得内容类型引用后,您可以检查其 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]);
    }
}

You can use the ContentType property of an SPListItem. If you want all content types in a list, you can use the ContentTypes property of an SPList. Once you have a content type reference, you can check its Fields property to get the columns.

Content Types for a list item:

SPContentType contentType = myListItem.ContentType;

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

Content Types for a list:

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]);
    }
}
南风起 2024-10-27 12:10:13

获取代表您的文档库的列表。一旦你有了这个,你就可以查看这些列。我通常使用这种方法:

SPWeb web = SPContext.Current.Web;  
SPList list = web.Lists["Your list name"];  
foreach (String field in list.DefaultView.ViewFields)  
{  
   //whatever
}

我相信这会为您提供默认视图的所有列。您还可以使用此方法:

SPWeb web = SPContext.Current.Web;  
SPList list = web.Lists["Your list name"];  
foreach (SPField field in list.Fields)  
{  
   //whatever
}

无论视图如何,它都会为您提供列表(库)中所有字段的信息。

Get the list that represents your document library. Once you have this you can look at the columns. I typically use this method:

SPWeb web = SPContext.Current.Web;  
SPList list = web.Lists["Your list name"];  
foreach (String field in list.DefaultView.ViewFields)  
{  
   //whatever
}

Which I believe gives you all the columns for the default view. You can also use this method:

SPWeb web = SPContext.Current.Web;  
SPList list = web.Lists["Your list name"];  
foreach (SPField field in list.Fields)  
{  
   //whatever
}

Which will give you info for all fields in the list (library) regardless of the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文