Пример #1
0
 //GetOne
 internal void GetOne(int itemId)
 {
     using (var client = new SPHttpClient(webUri, userName, password))
     {
         var listTitle = "HttpClientList";
         //var itemId = 7;
         var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items({2})", webUri, listTitle, itemId);
         var data        = client.ExecuteJson(endpointUrl);
         Console.WriteLine("Column 1: " + data["d"]["Title"] + ". Column 2: " + data["d"]["Somecolumn"] + ". - id: " + data["d"]["ID"]);
     }
 }
Пример #2
0
 //VERBS
 //GetAll
 internal void Get()
 {
     using (var client = new SPHttpClient(webUri, userName, password))
     {
         var listTitle   = "HttpClientList";
         var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items?$select=ID%2CTitle%2CSomecolumn", webUri, listTitle);
         var data        = client.ExecuteJson(endpointUrl);
         foreach (var item in data["d"]["results"])
         {
             Console.WriteLine(item["Title"] + " - " + "id: " + item["ID"]);
         }
     }
 }
Пример #3
0
 //Delete
 internal void Delete(int itemId)
 {
     using (var client = new SPHttpClient(webUri, userName, password))
     {
         var listTitle = "HttpClientList";
         //var itemId = 2;
         var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items({2})", webUri, listTitle, itemId);
         var headers     = new Dictionary <string, string>();
         headers["IF-MATCH"]      = "*";
         headers["X-HTTP-Method"] = "DELETE";
         client.ExecuteJson(endpointUrl, HttpMethod.Post, headers, default(string));
         Console.WriteLine("Task item has been deleted");
     }
 }
Пример #4
0
 //Put
 internal void Put(string title, string value, int itemId)
 {
     using (var client = new SPHttpClient(webUri, userName, password))
     {
         var listTitle = "HttpClientList";
         //var itemId = 6;
         var itemPayload = new { __metadata = new { type = "SP.Data.HttpClientListListItem" },
                                 //All the columns goes here comma seperetad
                                 Title      = title,
                                 Somecolumn = value };
         var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items({2})", webUri, listTitle, itemId);
         var headers     = new Dictionary <string, string>();
         headers["IF-MATCH"]      = "*";
         headers["X-HTTP-Method"] = "MERGE";
         client.ExecuteJson(endpointUrl, HttpMethod.Post, headers, itemPayload);
         Console.WriteLine("Task item has been updated");
     }
 }
Пример #5
0
 //Post
 internal void Post(string title, string value)
 {
     using (var client = new SPHttpClient(webUri, userName, password))
     {
         var listTitle   = "HttpClientList";
         var itemPayload = new
         {
             __metadata = new
             {
                 type = "SP.Data.HttpClientListListItem"
             },
             //All the columns goes here comma seperetad
             Title      = title,
             Somecolumn = value
         };
         var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items", webUri, listTitle);
         var data        = client.ExecuteJson(endpointUrl, HttpMethod.Post, itemPayload);
         Console.WriteLine("Task item '{0}' has been created", data["d"]["Title"]);
     }
 }