Guest User

Untitled

a guest
Oct 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. // Variables used in this code:
  2. string url_site = "http://prod_01/human-resources/property/";
  3. string _user = "shpfarm";
  4. string _password = "******";
  5.  
  6. // CSOM Authentication:
  7. ClientContext clientContext = new ClientContext(url_site);
  8. CredentialCache myCache = new CredentialCache();
  9. myCache.Add(new Uri(url_site), "NTLM", new NetworkCredential(_user, _password));
  10. clientContext.Credentials = myCache;
  11.  
  12. try
  13. {
  14. string HolidayDate = DateTime.Today.ToString("yyyy-MM-dd");
  15. string holiday_list_URL = "http://prod_01/human-resources/property/Lists/Holidays/AllItems.aspx";
  16.  
  17. List lst_Holiday = clientContext.Web.GetList(holiday_list_URL);
  18. clientContext.Load(lst_Holiday);
  19. Console.WriteLine("List called succesfully");
  20.  
  21. // Query: Get if current date is a holiday:
  22. CamlQuery cmlQueryHoliday = new CamlQuery();
  23. cmlQueryHoliday.ViewXml = string.Format(@"<View>
  24. <Query>
  25. <Where>
  26. <Eq>
  27. <FieldRef Name='HolidayDate' />
  28. <Value IncludeTimeValue='TRUE' Type='DateTime'>{0}</Value>
  29. </Eq>
  30. </Where>
  31. </Query>
  32. </View>", HolidayDate);
  33. ListItemCollection colItems = lst_Holiday.GetItems(cmlQueryHoliday);
  34. clientContext.Load(colItems);
  35. clientContext.ExecuteQuery();
  36. }
  37. catch (Exception ex)
  38. {
  39. Console.WriteLine("Error calling list (using URL): " + ex.ToString());
  40. }
  41.  
  42. in Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
  43. in Microsoft.SharePoint.Library.SPRequest.GetMetadataForUrl(String bstrUrl, Int32 METADATAFLAGS, Guid& pgListId, Int32& plItemId, Int32& plType, Object& pvarFileOrFolder)
  44. in Microsoft.SharePoint.SPWeb.GetList(String strUrl)
  45. in Microsoft.SharePoint.ServerStub.SPWebServerStub.InvokeMethod(Object target, String methodName, XmlNodeList xmlargs, ProxyContext proxyContext, Boolean& isVoid)
  46. in Microsoft.SharePoint.Client.ServerStub.InvokeMethodWithMonitoredScope(Object target, String methodName, XmlNodeList args, ProxyContext proxyContext, Boolean& isVoid)
  47. in Microsoft.SharePoint.Client.ClientMethodsProcessor.InvokeMethod(Object obj, String methodName, XmlNodeList xmlargs, Boolean& isVoid)
  48. in Microsoft.SharePoint.Client.ClientMethodsProcessor.GetObjectFromObjectPath(XmlElement xe)
  49. in Microsoft.SharePoint.Client.ClientMethodsProcessor.GetObjectFromObjectPathId(String objectPathId)
  50. in Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessInstantiateObjectPath(XmlElement xe)
  51. in Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessOne(XmlElement xe)
  52. in Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStatements(XmlNode xe)
  53. in Microsoft.SharePoint.Client.ClientMethodsProcessor.Process()
Add Comment
Please, Sign In to add comment