PageRenderTime 36ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/SPALM.SharePointSoftwareFactory/Snippets/CSharp/SharePoint Software Factory 2010/Lists and Libraries/Set default ContentType on a list.snippet

#
Unknown | 70 lines | 68 code | 2 blank | 0 comment | 0 complexity | a5ba3904d10a72459900956e2f892ac8 MD5 | raw file
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3. <CodeSnippet Format="1.0.0">
  4. <Header>
  5. <SnippetTypes>
  6. <SnippetType>Expansion</SnippetType>
  7. </SnippetTypes>
  8. <Title>Set default ContentType on a list</Title>
  9. <Author>Ayman El-Hattab http://ayman-elhattab.blogspot.com
  10. </Author>
  11. <Description>
  12. </Description>
  13. <HelpUrl>http://SPCodeSnippets.codeplex.com</HelpUrl>
  14. <Shortcut>
  15. </Shortcut>
  16. </Header>
  17. <Snippet>
  18. <Declarations>
  19. <Object Editable="true">
  20. <ID>defaultContentType</ID>
  21. <ToolTip>defaultContentType</ToolTip>
  22. <Default>defaultContentType</Default>
  23. <Function>
  24. </Function>
  25. <Type>string</Type>
  26. </Object>
  27. <Object Editable="true">
  28. <ID>list</ID>
  29. <ToolTip>SPList</ToolTip>
  30. <Default>list</Default>
  31. <Function>
  32. </Function>
  33. <Type>SPList</Type>
  34. </Object>
  35. <Literal Editable="true">
  36. <ID>defaultContentTypeName</ID>
  37. <ToolTip>Default ContentType name</ToolTip>
  38. <Default>DefaultContentTypeName</Default>
  39. <Function>
  40. </Function>
  41. </Literal>
  42. <Literal Editable="true">
  43. <ID>folder</ID>
  44. <ToolTip>SPFolder</ToolTip>
  45. <Default>folder</Default>
  46. <Function>
  47. </Function>
  48. </Literal>
  49. <Literal Editable="true">
  50. <ID>orderedContentTypes</ID>
  51. <ToolTip>orderedContentTypes</ToolTip>
  52. <Default>orderedContentTypes</Default>
  53. <Function>
  54. </Function>
  55. </Literal>
  56. </Declarations>
  57. <Code Language="csharp"><![CDATA[
  58. SPContentType $defaultContentType$ = $list$.ContentTypes["$defaultContentTypeName$"];
  59. $list$.ContentTypesEnabled = true;
  60. SPFolder $folder$ = $list$.RootFolder;
  61. SPContentType[] $orderedContentTypes$ = new SPContentType[1];
  62. $orderedContentTypes$[0] = $defaultContentType$;
  63. $folder$.UniqueContentTypeOrder = $orderedContentTypes$;
  64. $folder$.Update();
  65. ]]></Code>
  66. </Snippet>
  67. </CodeSnippet>
  68. </CodeSnippets>