PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/SPALM.SharePointSoftwareFactory/Snippets/CSharp/SharePoint Software Factory 2010/ListItems/Create a list item (Optimized).snippet

#
Unknown | 62 lines | 61 code | 1 blank | 0 comment | 0 complexity | d86dbb9ea3c844bbaaf2b4b404a5e037 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>Create a list item (Optimized)</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. <Literal Editable="true">
  20. <ID>MyTitle</ID>
  21. <ToolTip>MyTitle</ToolTip>
  22. <Default>MyTitle</Default>
  23. <Function>
  24. </Function>
  25. </Literal>
  26. <Literal Editable="true">
  27. <ID>EmptyQuery</ID>
  28. <ToolTip>EmptyQuery</ToolTip>
  29. <Default>EmptyQuery</Default>
  30. <Function>
  31. </Function>
  32. </Literal>
  33. <Object Editable="true">
  34. <ID>q</ID>
  35. <ToolTip>q</ToolTip>
  36. <Default>query</Default>
  37. <Function>
  38. </Function>
  39. <Type>SPQuery</Type>
  40. </Object>
  41. <Object Editable="true">
  42. <ID>item</ID>
  43. <ToolTip>SPListItem</ToolTip>
  44. <Default>item</Default>
  45. <Function>
  46. </Function>
  47. <Type>SPListItem</Type>
  48. </Object>
  49. </Declarations>
  50. <Code Language="csharp"><![CDATA[
  51. const string $EmptyQuery$ = "0";
  52. SPQuery $q$ = new SPQuery();
  53. $q$.Query = $EmptyQuery$;
  54. SPListItem $item$ = list.GetItems($q$).Add();
  55. $item$["Title"] = "$MyTitle$";
  56. $item$.Update();
  57. // Do not use SPList.Items.Add as this will get all items in the list before adding a new SPListItem. ( Thanks to Rob Garret )
  58. ]]></Code>
  59. </Snippet>
  60. </CodeSnippet>
  61. </CodeSnippets>