PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/SPALM.SharePointSoftwareFactory/Snippets/CSharp/SharePoint Software Factory 2010/Lists and Libraries/Add Field to List.snippet

#
Unknown | 62 lines | 62 code | 0 blank | 0 comment | 0 complexity | 72208a4d5bc979160faa5c4985577b0a 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>Add Field to List</Title>
  9. <Author>Torsten Mandelkow</Author>
  10. <Description>Creates a field in the collection based on the specified display name, field type, and Boolean value.</Description>
  11. <HelpUrl>http://msdn.microsoft.com/en-us/library/ms472869.aspx</HelpUrl>
  12. <Shortcut>AddFieldToList</Shortcut>
  13. </Header>
  14. <Snippet>
  15. <Declarations>
  16. <Literal Editable="true">
  17. <ID>FieldName</ID>
  18. <ToolTip>Field name</ToolTip>
  19. <Default>Fieldname</Default>
  20. <Function>
  21. </Function>
  22. </Literal>
  23. <Literal Editable="true">
  24. <ID>ListName</ID>
  25. <ToolTip>List name</ToolTip>
  26. <Default>ListName</Default>
  27. <Function>
  28. </Function>
  29. </Literal>
  30. <Literal Editable="true">
  31. <ID>WebName</ID>
  32. <ToolTip>Web name</ToolTip>
  33. <Default>WebName</Default>
  34. <Function>
  35. </Function>
  36. </Literal>
  37. <Object Editable="true">
  38. <ID>collFields</ID>
  39. <ToolTip>collFields</ToolTip>
  40. <Default>collFields</Default>
  41. <Function>
  42. </Function>
  43. <Type>SPFieldCollection</Type>
  44. </Object>
  45. <Object Editable="true">
  46. <ID>oWeb</ID>
  47. <ToolTip>SPWeb object</ToolTip>
  48. <Default>web</Default>
  49. <Function>
  50. </Function>
  51. <Type>SPWeb</Type>
  52. </Object>
  53. </Declarations>
  54. <Code Language="csharp"><![CDATA[using (SPWeb $oWeb$ = SPContext.Current.Site.AllWebs["$WebName$"])
  55. {
  56. SPFieldCollection $collFields$ = $oWeb$.Lists["$ListName$"].Fields;
  57. $collFields$.Add("$FieldName$", Microsoft.SharePoint.SPFieldType.Text,
  58. true);
  59. }]]></Code>
  60. </Snippet>
  61. </CodeSnippet>
  62. </CodeSnippets>