0

我创建了一个站点,并且正在通过 Sharepoint 2010 Web 服务以编程方式添加文档库的内容类型。我能够做到这一点,但是我还想启用/允许文档库的内容类型 - 代码如下: -

    Lists.Lists lists = new Lists.Lists();
    lists.Url = sharepointWebSiteUrl + "/_vti_bin/lists.asmx";
    lists.Credentials = System.Net.CredentialCache.DefaultCredentials;

    // Create document library templateid 101 is a document library
    System.Xml.XmlNode result = lists.AddList(documentLibraryName, documentLibraryName, 101);
    XmlDocument xmlDoc = new XmlDocument();
    XmlNode xnProperties = xmlDoc.CreateNode(XmlNodeType.Element, "List", "");

    //Allow/enable content types for the document library
    XmlAttribute xnAllowContentTypesAttribute = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "AllowContentTypes", "");
    xnAllowContentTypesAttribute.Value = "True";
    xnProperties.Attributes.Append(xnAllowContentTypesAttribute);

    XmlAttribute xnContentTypesEnabledAttribute = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "ContentTypesEnabled", "");
    xnContentTypesEnabledAttribute.Value = "True";
    xnProperties.Attributes.Append(xnContentTypesEnabledAttribute);

    XmlNode updateList = lists.UpdateList(documentLibraryName, xnProperties, null, null, null, null);

    //Add the content types
    XmlNode xmlNodeContentType = null;
    xmlNodeContentType = lists.ApplyContentTypeToList(sharepointWebSiteUrl, Constants.ReportDocumentLibraryContentTypeId, documentLibraryName);
    xmlNodeContentType = lists.ApplyContentTypeToList(sharepointWebSiteUrl, Constants.DataSourceDocumentLibraryContentTypeId, documentLibraryName);
    xmlNodeContentType = lists.ApplyContentTypeToList(sharepointWebSiteUrl, Constants.ModelDocumentLibraryContentTypeId, documentLibraryName);

以上创建文档库并添加内容类型,但不允许/启用文档库的内容类型。

提醒一下,我需要通过 Web 服务执行此操作 -而不是通过对象模型

4

1 回答 1

0

根据msdn,您应该尝试EnableContentTypes属性名称。

于 2014-02-25T19:29:37.810 回答