PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Unknown | 70 lines | 68 code | 2 blank | 0 comment | 0 complexity | ad0fed905805aaac09cb2267645f22aa 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 as Xml</Title>
  9. <Author>Torsten Mandelkow</Author>
  10. <Description>Creates a field based on the specified schema, Boolean value, and field options.</Description>
  11. <HelpUrl>http://msdn.microsoft.com/en-us/library/ms457586.aspx</HelpUrl>
  12. <Shortcut>AddFieldAsXmlToList</Shortcut>
  13. </Header>
  14. <Snippet>
  15. <Declarations>
  16. <Object Editable="true">
  17. <ID>oWebsite</ID>
  18. <ToolTip>SPWeb Object</ToolTip>
  19. <Default>oWeb</Default>
  20. <Function>
  21. </Function>
  22. <Type>SPWeb</Type>
  23. </Object>
  24. <Object Editable="true">
  25. <ID>collFields</ID>
  26. <ToolTip>collFields</ToolTip>
  27. <Default>collFields</Default>
  28. <Function>
  29. </Function>
  30. <Type>SPFieldCollection</Type>
  31. </Object>
  32. <Literal Editable="true">
  33. <ID>strNewField</ID>
  34. <ToolTip>New Field</ToolTip>
  35. <Default>strNewField</Default>
  36. <Function>
  37. </Function>
  38. </Literal>
  39. <Literal Editable="true">
  40. <ID>WebName</ID>
  41. <ToolTip>Web Name</ToolTip>
  42. <Default>WebName</Default>
  43. <Function>
  44. </Function>
  45. </Literal>
  46. <Literal Editable="true">
  47. <ID>ListName</ID>
  48. <ToolTip>ListName</ToolTip>
  49. <Default>ListName</Default>
  50. <Function>
  51. </Function>
  52. </Literal>
  53. </Declarations>
  54. <Code Language="csharp"><![CDATA[using (SPWeb $oWebsite$ = SPContext.Current.Site.AllWebs["$WebName$"])
  55. {
  56. SPFieldCollection $collFields$ = $oWebsite$.Lists["$ListName$"].Fields;
  57. string $strNewField$ = "<Field Type=\"Calculated\" " +
  58. "DisplayName=\"New_Field_Display_Name\" ResultType=\"Currency\" " +
  59. "ReadOnly=\"TRUE\" Name=\"New_Field_Internal_Name\">" +
  60. "<Formula>=Currency_Field_Name*100</Formula>" +
  61. "<FieldRefs><FieldRef Name=\"Currency_Field_Name\" />" +
  62. "</FieldRefs></Field>";
  63. $collFields$.AddFieldAsXml($strNewField$);
  64. }
  65. ]]></Code>
  66. </Snippet>
  67. </CodeSnippet>
  68. </CodeSnippets>