none
Add allowed content type in document set RRS feed

  • Question

  • I'm developing a feature with 2 content types; A document set and a picture

    I need that my document set allow my second content type Picture.

    I've tested this but nothing happens if Igo to manage document set

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <!-- Parent ContentType: Document Set (0x0120D520) -->
      <ContentType ID="0x0120D520003E4980F3009045648C71163A63AFE9C1" Name="DocumentSetGeolocation" Group="test" Description="My Content Type" Inherits="TRUE" Version="0">
        <FieldRefs>
          <FieldRef ID="{99afd525-b766-4249-b933-de94c987d218}" DisplayName="N° chantier" Required="FALSE" Name="N_chantier" />
        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes">
            <act:AllowedContentTypes xmlns:act="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes" LastModified="1/1/2010 08:00:00 AM">
              <AllowedContentType id="0x010102003139F2673D35495C861AF26048B55D78" />
            </act:AllowedContentTypes>
          </XmlDocument>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/defaultdocuments">
            <dd:DefaultDocuments xmlns:dd="http://schemas.microsoft.com/office/documentsets/defaultdocuments" AddSetName="TRUE" LastModified="1/1/2010 08:00:00 AM">
              <DefaultDocument name="PictureGeolocation.xsn" idContentType="0x010102003139F2673D35495C861AF26048B55D78" />
            </dd:DefaultDocuments>
          </XmlDocument>
        </XmlDocuments>
      </ContentType>
    </Elements>


    Finally i add allowed content type and column in my event receiver feature activated

    SPSite site = properties.Feature.Parent as SPSite;
                    using (SPWeb web = site.RootWeb)
                    {
                        //retrieve docset contenttype
                        SPContentType CTDocumentSet = web.ContentTypes["DocumentSetGeolocation"];
                        //create the new document set contenttype
                        SPContentType CTPicture = web.ContentTypes["PictureGeolocation"];
                        //get a an instance of DocumentSetTemplate for the document set geolocation
                        DocumentSetTemplate newDocumentSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(CTDocumentSet);
                        //remove allowable content type Document
                        newDocumentSetTemplate.AllowedContentTypes.Remove(web.ContentTypes["Document"].Id);
                        //add allowable content types
                        newDocumentSetTemplate.AllowedContentTypes.Add(CTPicture.Id); 
                        //add a shareable property
                        Guid guidChantier = new Guid("99afd525-b766-4249-b933-de94c987d218");
                        newDocumentSetTemplate.SharedFields.Add(CTDocumentSet.Fields[guidChantier]);
                        newDocumentSetTemplate.Update(true);
                        CTDocumentSet.Update();
                        web.Update();
                    }

    • Edited by bender1986 Thursday, January 14, 2016 9:32 AM
    Wednesday, January 13, 2016 9:13 PM

All replies

  • Hi,

    Please add the allow content type in SharePoint UI, then using the following code to check the SchemaXml of the "DocumentSetGeolocation" content type, then reference this content type definition.

    using (SPSite site = new SPSite("http://sp2013"))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    		SPContentTypeCollection allContentTypes = web.ContentTypes;
    		
    		foreach (SPContentType objContentType in allContentTypes)
    		{
    			if (objContentType.Name == "DocumentSetGeolocation")
    			{
    				Console.WriteLine(objContentType.SchemaXml);
    			}
    			 
    		}
    		Console.ReadKey();		
    	}
    }

    Or you can try to deploy the "PictureGeolocation" content type first, and then deploy the "DocumentSetGeolocation" content type.

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, January 14, 2016 7:33 AM
    Moderator
  • Hi thanks for your check.

    Effectively i don't see it inside.

    Do you have an explication?

    Here is my xml returned:

    	<?xml version="1.0"?>
    
    	-<ContentType PushDownChangedResourceFilesOnly="TRUE" ProgId="Sharepoint.DocumentSet" Version="1" Description="My Content Type" Group="eiffage" Name="DocumentSetGeolocation" ID="0x0120D520003E4980F3009045648C71163A63AFE9C1">
    
    	<Folder TargetName="_cts/DocumentSetGeolocation"/>
    
    
    	-<Fields>
    
    
    	-<Field Group="_Hidden" Name="ContentType" ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Customization="" PIAttribute="ContentTypeID" PITarget="MicrosoftWindowsSharePointServices" RenderXMLUsingPattern="TRUE" Sortable="FALSE" Sealed="TRUE" DisplayName="Content Type" Type="Computed" StaticName="ContentType" SourceID="http://schemas.microsoft.com/sharepoint/v3">
    
    
    	+<FieldRefs>
    
    
    	-<DisplayPattern>
    
    
    	-<MapToContentType>
    
    	<Column Name="ContentTypeId"/>
    
    	</MapToContentType>
    
    	</DisplayPattern>
    
    	</Field>
    
    	<Field Group="_Hidden" Name="ItemChildCount" ID="{b824e17e-a1b3-426e-aecf-f0184d900485}" Customization="" Sortable="FALSE" DisplayName="Item Child Count" Type="Lookup" StaticName="ItemChildCount" SourceID="http://schemas.microsoft.com/sharepoint/v3" JoinType="INNER" JoinRowOrdinal="0" JoinColName="DoclibRowId" ShowField="ItemChildCount" FieldRef="ID" List="Docs" Hidden="FALSE" Filterable="FALSE" ReadOnly="TRUE" DisplaceOnUpgrade="TRUE"/>
    
    	<Field Group="_Hidden" Name="FolderChildCount" ID="{960ff01f-2b6d-4f1b-9c3f-e19ad8927341}" Customization="" Sortable="FALSE" DisplayName="Folder Child Count" Type="Lookup" StaticName="FolderChildCount" SourceID="http://schemas.microsoft.com/sharepoint/v3" JoinType="INNER" JoinRowOrdinal="0" JoinColName="DoclibRowId" ShowField="FolderChildCount" FieldRef="ID" List="Docs" Hidden="FALSE" Filterable="FALSE" ReadOnly="TRUE" DisplaceOnUpgrade="TRUE"/>
    
    	<Field Group="_Hidden" Name="Title" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Customization="" DisplayName="Title" Type="Text" StaticName="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3" Hidden="TRUE" FromBaseType="TRUE" Required="FALSE"/>
    
    	<Field Group="_Hidden" Name="FileLeafRef" ID="{8553196d-ec8d-4564-9861-3dbe931050c8}" Customization="" DisplayName="Name" Type="File" StaticName="FileLeafRef" SourceID="http://schemas.microsoft.com/sharepoint/v3" JoinType="INNER" JoinRowOrdinal="0" JoinColName="DoclibRowId" ShowField="LeafName" FieldRef="ID" List="Docs" Hidden="FALSE" Required="TRUE" AuthoringInfo="(for use in forms)" ShowInVersionHistory="FALSE" ShowInFileDlg="FALSE"/>
    
    	<Field Description="A description of the Document Set" Group="_Hidden" Name="DocumentSetDescription" ID="{CBB92DA4-FD46-4C7D-AF6C-3128C2A5576E}" Customization="" Sealed="TRUE" DisplayName="Description" Type="Note" StaticName="DocumentSetDescription" SourceID="http://schemas.microsoft.com/sharepoint/v3" Hidden="FALSE" Required="FALSE" ShowInEditForm="TRUE" ShowInNewForm="TRUE" CanToggleHidden="TRUE" UnlimitedLengthInDocumentLibrary="TRUE" NumLines="5" Indexed="FALSE"/>
    
    	<Field Group="Eiffage" Name="N_chantier" ID="{99afd525-b766-4249-b933-de94c987d218}" Customization="" DisplayName="N° chantier" Type="Text" Required="FALSE"/>
    
    	</Fields>
    
    
    	-<XmlDocuments>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/sharedfields">
    
    	<SharedFields LastModified="1/1/1 0:00:01 AM" xmlns="http://schemas.microsoft.com/office/documentsets/sharedfields"/>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/defaultdocuments">
    
    	<DefaultDocuments LastModified="1/1/1 0:00:01 AM" xmlns="http://schemas.microsoft.com/office/documentsets/defaultdocuments" AddSetName=""/>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/welcomepagefields">
    
    	<WelcomePageFields LastModified="1/1/1 0:00:01 AM" xmlns="http://schemas.microsoft.com/office/documentsets/welcomepagefields"/>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/welcomepageview">
    
    	<WelcomePageView LastModified="1/1/1 0:00:01 AM" xmlns="http://schemas.microsoft.com/office/documentsets/welcomepageview"/>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events">
    
    
    	-<spe:Receivers xmlns:spe="http://schemas.microsoft.com/sharepoint/events">
    
    
    	-<Receiver>
    
    	<Name>DocumentSet ItemUpdated</Name>
    
    	<Synchronization>Synchronous</Synchronization>
    
    	<Type>10002</Type>
    
    	<SequenceNumber>100</SequenceNumber>
    
    	<Url/>
    
    	<Assembly>Microsoft.Office.DocumentManagement, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
    
    	<Class>Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetEventReceiver</Class>
    
    	<Data/>
    
    	<Filter/>
    
    	</Receiver>
    
    
    	-<Receiver>
    
    	<Name>DocumentSet ItemAdded</Name>
    
    	<Synchronization>Synchronous</Synchronization>
    
    	<Type>10001</Type>
    
    	<SequenceNumber>100</SequenceNumber>
    
    	<Url/>
    
    	<Assembly>Microsoft.Office.DocumentManagement, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
    
    	<Class>Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver</Class>
    
    	<Data/>
    
    	<Filter/>
    
    	</Receiver>
    
    
    	-<Receiver>
    
    	<Name>DocumentSet ItemAdding</Name>
    
    	<Synchronization>Synchronous</Synchronization>
    
    	<Type>1</Type>
    
    	<SequenceNumber>100</SequenceNumber>
    
    	<Url/>
    
    	<Assembly>Microsoft.Office.DocumentManagement, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
    
    	<Class>Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver</Class>
    
    	<Data/>
    
    	<Filter/>
    
    	</Receiver>
    
    
    	-<Receiver>
    
    	<Name>DocumentSet ItemUpdating</Name>
    
    	<Synchronization>Synchronous</Synchronization>
    
    	<Type>2</Type>
    
    	<SequenceNumber>100</SequenceNumber>
    
    	<Url/>
    
    	<Assembly>Microsoft.Office.DocumentManagement, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
    
    	<Class>Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetItemsEventReceiver</Class>
    
    	<Data/>
    
    	<Filter/>
    
    	</Receiver>
    
    	</spe:Receivers>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes">
    
    
    	-<act:AllowedContentTypes LastModified="01/13/2016 14:55:10" xmlns:act="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes">
    
    	<AllowedContentType id="0x0101"/>
    
    	</act:AllowedContentTypes>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
    
    
    	-<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
    
    	<Display>ListForm</Display>
    
    	<Edit>ListForm</Edit>
    
    	<New>DocSetDisplayForm</New>
    
    	</FormTemplates>
    
    	</XmlDocument>
    
    
    	-<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
    
    
    	-<FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
    
    	<New>_layouts/15/NewDocSet.aspx</New>
    
    	</FormUrls>
    
    	</XmlDocument>
    
    	</XmlDocuments>
    

    Thursday, January 14, 2016 8:28 AM
  • Hi,

    I mean, you can add the allowed content type in UI, like this:

    Then check definition using Code.

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, January 14, 2016 10:26 AM
    Moderator