1
我正在使用SharePoint 2010和Visual Studio 2010. VS 2010使通过对话框添加列表定义非常容易,但只允许通过对话框添加一种内容类型对话框,但是我需要添加两个,我该怎么做?从两种内容类型(SharePoint)创建列表定义
在此先感谢!
干杯!
我正在使用SharePoint 2010和Visual Studio 2010. VS 2010使通过对话框添加列表定义非常容易,但只允许通过对话框添加一种内容类型对话框,但是我需要添加两个,我该怎么做?从两种内容类型(SharePoint)创建列表定义
在此先感谢!
干杯!
您可以通过代码将内容类型与列表相关联。我总是这样做用这种方法:
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);