Advertisement
Guest User

Untitled

a guest
Dec 29th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.Xml;
  5.  
  6. namespace SharePoint.Client
  7. {
  8. public class ListsClient : IDisposable
  9. {
  10. public ListsClient(Uri webUri, ICredentials credentials)
  11. {
  12. _client = new Lists.Lists();
  13. _client.Credentials = credentials;
  14. _client.Url = webUri + "/_vti_bin/Lists.asmx";
  15. }
  16.  
  17. public ListsClient(Uri webUri)
  18. {
  19. _client = new Lists.Lists();
  20. _client.Url = webUri + "/_vti_bin/Lists.asmx";
  21. }
  22.  
  23.  
  24. /// <summary>
  25. /// Create a List Item
  26. /// </summary>
  27. /// <param name="listName">List Name</param>
  28. /// <param name="propertyValues">List Item properties</param>
  29. /// <returns></returns>
  30. public XmlNode CreateListItem(string listName,Dictionary<string,string> propertyValues)
  31. {
  32. var payload = new XmlDocument();
  33. var updates = payload.CreateElement("Batch");
  34. updates.SetAttribute("OnError", "Continue");
  35. var method = payload.CreateElement("Method");
  36. method.SetAttribute("ID", "1");
  37. method.SetAttribute("Cmd", "New");
  38. foreach (var propertyValue in propertyValues)
  39. {
  40. var field = payload.CreateElement("Field");
  41. field.SetAttribute("Name", propertyValue.Key);
  42. field.InnerText = propertyValue.Value;
  43. method.AppendChild(field);
  44. }
  45. updates.AppendChild(method);
  46. return _client.UpdateListItems(listName, updates);
  47. }
  48.  
  49.  
  50.  
  51. public void Dispose()
  52. {
  53. _client.Dispose();
  54. GC.SuppressFinalize(this);
  55. }
  56.  
  57.  
  58. protected Lists.Lists _client; //SharePoint Web Services Lists proxy
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement