Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从两种内容类型(SharePoint)创建列表定义_Sharepoint - Fatal编程技术网

从两种内容类型(SharePoint)创建列表定义

从两种内容类型(SharePoint)创建列表定义,sharepoint,Sharepoint,我目前正在使用SharePoint 2010和Visual Studio 2010。VS2010使通过对话框添加列表定义变得非常简单,但只允许通过对话框添加一种内容类型,但是我需要添加两种,如何才能做到这一点 提前谢谢 干杯 您可以通过代码将内容类型与列表相关联。我总是用这种方法: private void VerifyListContentTypeAssociation(SPList list, string contentType) { SPContentTy

我目前正在使用SharePoint 2010和Visual Studio 2010。VS2010使通过对话框添加列表定义变得非常简单,但只允许通过对话框添加一种内容类型,但是我需要添加两种,如何才能做到这一点

提前谢谢


干杯

您可以通过代码将内容类型与列表相关联。我总是用这种方法:

    private void VerifyListContentTypeAssociation(SPList list, string contentType)
    {
        SPContentTypeId contentTypeId = new SPContentTypeId(contentType);
        list.ContentTypesEnabled = true;
        SPContentTypeId matchContentTypeId = list.ContentTypes.BestMatch(contentTypeId);

        if (matchContentTypeId.Parent.CompareTo(contentTypeId) != 0)
        {
            SPContentType ct = list.ParentWeb.AvailableContentTypes[contentTypeId];
            list.ContentTypes.Add(ct);
            list.Update();
        }
    }
您可以在功能接收器中使用此功能,例如:

string contentTypeID = "0x010056eb9d8ddb324c92865eceef8a97c811";
SPList myList = web.Lists["MyList"];
VerifyListContentTypeAssociation(myList, contentTypeID);

您可以通过代码将内容类型与列表关联。我总是用这种方法:

    private void VerifyListContentTypeAssociation(SPList list, string contentType)
    {
        SPContentTypeId contentTypeId = new SPContentTypeId(contentType);
        list.ContentTypesEnabled = true;
        SPContentTypeId matchContentTypeId = list.ContentTypes.BestMatch(contentTypeId);

        if (matchContentTypeId.Parent.CompareTo(contentTypeId) != 0)
        {
            SPContentType ct = list.ParentWeb.AvailableContentTypes[contentTypeId];
            list.ContentTypes.Add(ct);
            list.Update();
        }
    }
您可以在功能接收器中使用此功能,例如:

string contentTypeID = "0x010056eb9d8ddb324c92865eceef8a97c811";
SPList myList = web.Lists["MyList"];
VerifyListContentTypeAssociation(myList, contentTypeID);