Add Content Type To List

Adds a specified content type to a SharePoint list.

Reference Information
Release Status : Stable
Alias Name : Action.AddContentTypeToList
Full Reference Name : Collaboris.Saf.Actions.Wss.ContentType.AddContentTypeToList
Assembly Name : Collaboris.Saf.Actions.Wss
Remarks : If the content type is not in the available content types list it will not be added unless you specify 'ListItemUrl' in the entity.
Undo Implementation? : This action has no Undo implementation.
Download Samples for AddContentTypeToList : Collaboris.Saf.Actions.Wss.ContentType.AddContentTypeToList.zip
Download Samples for ALL Actions : AllSamples.zip

Properties
Name Description Example Value Output Required
DisableDo Boolean. Determines whether to disable the 'Do' on the Action. If 'DisableDo' is set to 'True' then the action will be skipped. false false false
DisableUndo Boolean. Determines whether to disable the 'Undo' on the Action. If 'DisableUndo' is set to 'True' then the action will be skipped. false false false
EntityList Defines an array of Collaboris.Saf.Actions.Wss.Entities.ContentTypeToListMapping.

Note :
Entities are the method in which parameters can be supplied to the Action. Many instances of an entity can be passed in. (Please see the XML examples to understand how to configure an entity with values).
Please refer to the documented types for samples. false false
ID Guid. A unique identifier for the instance of the action. If an ID is not supplied then SAF will create a new one. {47B640DD-64A9-493b-8445-789FC0D05FF1} false true
StopOnDoException Boolean. A bool indicating whether to stop processing if an exception is encountered during the 'Do' operation of the Action. true false false
StopOnUndoException Boolean. A bool indicating whether to stop processing if an exception is encountered during the 'Undo' operation of the Action. true false false

AddContentTypeToList Examples

This example illustrates how to call a Templated Macro from an MSBuild project. (Please see the 'Templated Macro' tab.)

<?xml version="1.0" encoding="utf-8"?>
<!-- Defines a 'SAF Macro' containiing 'Actions' to be run on 'Do' and 'Undo' -->
<!-- Please visit http://www.collaboris.co.uk/Saf/Doc/default.html for more information. -->
<Project DefaultTargets="Do" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask AssemblyName="Collaboris.Saf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195" TaskName="Collaboris.Saf.Adapters.MSBuild.SAF" />
  <ItemGroup>
    <Macros Include="Collaboris.Saf.Actions.Wss.ContentType.AddContentTypeToList.macroTemplate">
      <disabledo>false</disabledo>
      <disableundo>false</disableundo>
      <addifunavailable>true</addifunavailable>
      <contenttypename>Form</contenttypename>
      <enablecontenttypesonlist>true</enablecontenttypesonlist>
      <listname>Pages</listname>
      <id>{47B640DD-64A9-493b-8445-789FC0D05FF1}</id>
      <stopondoexception>true</stopondoexception>
      <stoponundoexception>true</stoponundoexception>
      <Url>http://localhost:4422</Url>
      <InstanceId>{{156E17A5-A7BA-4e1f-8A48-1BC341A7C639}}</InstanceId>
    </Macros>
  </ItemGroup>
  <Target Name="Do">
    <SAF MacroPaths="@(Macros)" ProcessMode="Do" ContinueOnError="false" />
  </Target>
  <Target Name="Undo">
    <SAF MacroPaths="@(Macros)" ProcessMode="Undo" ContinueOnError="false" />
  </Target>
</Project>

This example illustrates how to create a macro directly with values inserted.

<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net" default-lazy-init="true">
  <object id="MacroToProcess" type="Macro">
    <constructor-arg name="templateid" value="{32ef82fb-44cf-4dd7-b93d-a713d9a5f237}" />
    <constructor-arg name="actions">
      <list element-type="IAction">
        <object id="AddContentTypeToListd4" type="Action.AddContentTypeToList" lazy-init="true">
          <property name="DisableDo" value="false" />
          <property name="DisableUndo" value="false" />
          <property name="EntityList">
            <object id="ContentTypeToListMapping1b" type="Entity.ContentTypeToListMapping" lazy-init="true">
              <property name="AddIfUnavailable" value="true" />
              <property name="ContentTypeName" value="Form" />
              <property name="EnableContentTypesOnList" value="true" />
              <property name="ListName" value="Pages" />
            </object>
          </property>
          <property name="ID" value="{47B640DD-64A9-493b-8445-789FC0D05FF1}" />
          <property name="StopOnDoException" value="true" />
          <property name="StopOnUndoException" value="true" />
        </object>
      </list>
    </constructor-arg>
  </object>
</objects>

This example illustrates how to create the Macro as a template, (so that it can be called via MSBuild or a Feature).

<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net" default-lazy-init="true">
  <object id="MacroToProcess" type="Macro">
    <constructor-arg name="templateid" value="{92b8049f-4bf4-44e0-a493-0e38fd016ee8}" />
    <constructor-arg name="actions">
      <list element-type="IAction">
        <object id="AddContentTypeToListac" type="Action.AddContentTypeToList" lazy-init="true">
          <property name="DisableDo" expression="Func.Eval('${disabledo}')" />
          <property name="DisableUndo" expression="Func.Eval('${disableundo}')" />
          <property name="EntityList">
            <object id="ContentTypeToListMapping9e" type="Entity.ContentTypeToListMapping" lazy-init="true">
              <property name="AddIfUnavailable" expression="Func.Eval('${addifunavailable}')" />
              <property name="ContentTypeName" expression="Func.Eval('${contenttypename}')" />
              <property name="EnableContentTypesOnList" expression="Func.Eval('${enablecontenttypesonlist}')" />
              <property name="ListName" expression="Func.Eval('${listname}')" />
            </object>
          </property>
          <property name="ID" expression="Func.Eval('${id}')" />
          <property name="StopOnDoException" expression="Func.Eval('${stopondoexception}')" />
          <property name="StopOnUndoException" expression="Func.Eval('${stoponundoexception}')" />
        </object>
      </list>
    </constructor-arg>
  </object>
</objects>

This example illustrates how to call a Templated Macro from a Feature Receiver. (Please see the 'Templated Macro' tab).

<?xml version="1.0" encoding="utf-8"?>
<Feature Id="{156E17A5-A7BA-4e1f-8A48-1BC341A7C639}" Title="SAF Sample Feature - 'Action.AddContentTypeToList'" Description="Sample Feature illustrating how to call and run 'AddContentTypeToList' from a SAF Macro." Version="12.0.0.0" Hidden="FALSE" Scope="Web" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/" ReceiverAssembly="Collaboris.Saf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195" ReceiverClass="Collaboris.Saf.Adapters.SafFeatureReceiver">
  <Properties>
    <!-- Defines a SAF Macro containiing Actions to be run on Do and Undo -->
    <!-- Please visit http://www.collaboris.co.uk/Saf/Doc/default.html for more information. -->
    <Property Key="MacroFile" Value="Collaboris.Saf.Actions.Wss.ContentType.AddContentTypeToList.macroTemplate" />
    <Property Key="InstanceId" Value="{156E17A5-A7BA-4e1f-8A48-1BC341A7C639}" />
    <Property Key="disabledo" Value="false" />
    <Property Key="disableundo" Value="false" />
    <Property Key="addifunavailable" Value="true" />
    <Property Key="contenttypename" Value="Form" />
    <Property Key="enablecontenttypesonlist" Value="true" />
    <Property Key="listname" Value="Pages" />
    <Property Key="id" Value="{47B640DD-64A9-493b-8445-789FC0D05FF1}" />
    <Property Key="stopondoexception" Value="true" />
    <Property Key="stoponundoexception" Value="true" />
    <!-- You can also define your own properties to be resolved by PlaceHolders in the Macro ... <Property Key="YourKey" Value="YourValue" /> -->
  </Properties>
</Feature>

This example illustrates how to call a Templated Macro from a custom Saf StsAdm Command. (Please see the 'Templated Macro' tab).

REM Defines a SAF Macro containiing Actions to be run on Do and/or Undo 
REM Please visit http://www.collaboris.co.uk/Projects/SafWiki/SAF_WIKI/Contents_Page.aspx for more information. 
REM IMPORTANT! If this macro needs a SharePoint context please amend the '-url http://localhost:4422' argument (below).
REM				 
REM            If the macro DOESN'T require a SharePoint context, simply remove the '-url http://localhost:4422' argument. 
SET STSADM=C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe

"%STSADM%" -o saf-run -macrofile Collaboris.Saf.Actions.Wss.ContentType.AddContentTypeToList.macroTemplate -mode "do" -url http://localhost:4422 -disabledo "false" -disableundo "false" -addifunavailable "true" -contenttypename "Form" -enablecontenttypesonlist "true" -listname "Pages" -id "{47B640DD-64A9-493b-8445-789FC0D05FF1}" -stopondoexception "true" -stoponundoexception "true"