Sharepoint Web服务 - 以编程方式允许/启用内容类型

时间:2014-02-25 19:23:53

标签: sharepoint sharepointdocumentlibrary contenttype

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

    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);

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

提醒一下,我需要通过网络服务来做到这一点 - 不是通过对象模型

1 个答案:

答案 0 :(得分:0)

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