Guest User

Untitled

a guest
Dec 15th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. public async Task GetItemsFromListByCaseNumber(string Case_Number)
  2. {
  3. byte[] responseString;
  4.  
  5. try
  6. {
  7. string requestUrl = "/Case Document/items?expand=fields&filter=fields/CaseNumber eq '" + Case_Number + "'";
  8. await PostRequestToSharepoint(requestUrl, HttpMethod.Get);
  9. }
  10. catch (Exception ex)
  11. {
  12. }
  13.  
  14. }
  15.  
  16. public async Task<Dictionary<String, JsonValue>> PostRequestToSharepoint(string url, HttpMethod method)
  17. {
  18. byte[] responseString;
  19. Dictionary<String, JsonValue> list = new Dictionary<String, JsonValue>();
  20. try
  21. {
  22. string accessToken = await new ServiceAPIConnection().GetToken();
  23. string requestUrl = sharepointURL + "/sites/albaabtech.sharepoint.com:/sites/hha:/lists/Case Document/items?$select=AppointmentID&$filter=AppointmentID eq 'APPXID100000745'";
  24.  
  25. // string requestUrl = sharepointURL + "/sites/albaabtech.sharepoint.com:/sites/hha:/lists" + url;
  26.  
  27. HttpClient client = new HttpClient();
  28.  
  29. HttpRequestMessage message = new HttpRequestMessage(method, requestUrl);
  30. message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  31. message.Headers.Authorization = new AuthenticationHeaderValue("Bearer",accessToken);
  32. HttpResponseMessage response = await client.SendAsync(message);
  33. if (response.IsSuccessStatusCode)
  34. {
  35. responseString = await response.Content.ReadAsByteArrayAsync();
  36.  
  37. //Dictionary<String, IJsonValue> listDict = new Dictionary<string, IJsonValue>();
  38. //ParseJson(JsonObject.Parse(Encoding.UTF8.GetString(responseString, 0, responseString.Length)), listDict); //parse the json payload we got back
  39.  
  40. //JsonArray lists = listDict["value"].GetArray(); // the "value" json structure contains the list metadata
  41.  
  42. //if (lists.Count > 0)
  43. //{
  44. // foreach (IJsonValue item in lists)
  45. // {
  46. // try
  47. // {
  48. // ParseJson(item.GetObject(), list);
  49. // }
  50. // catch
  51. // {
  52. // Do no crash the app if we cannot parse the payload for a list
  53. // }
  54. // }
  55. //}
  56. }
  57. //else
  58. // responseString = "Error in response";
  59. }
  60. catch (Exception ex)
  61. {
  62. // responseString = "Exception: " + ex.Message;
  63. }
  64.  
  65. return list;
  66.  
  67. }
Add Comment
Please, Sign In to add comment