Exemplo n.º 1
0
        //gavdcodeend 14

        //gavdcodebegin 15
        static void SpCsRestDeleteUserFromSecurityRoleInList(Uri webUri,
                                                             string userName, string password)
        {
            // Find the User
            int userId = 0;

            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/web/siteusers?$select=Id&" +
                                     "$filter=startswith(Title,'MOD')";
                var data = (JObject)client.ExecuteJson(endpointUrl, HttpMethod.Get,
                                                       myPayload);
                userId = int.Parse(data["d"]["results"][0]["Id"].ToString());
                Console.WriteLine(userId);
            }

            // Remove the User from the List
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/web/lists/GetByTitle" +
                                     "('NewListRestCs')/roleassignments/getbyprincipalid(principalid=" +
                                     userId + ")";
                IDictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("IF-MATCH", "*");
                headers.Add("X-HTTP-Method", "DELETE");
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Post,
                                              headers, myPayload);
                Console.WriteLine(data);
            }
        }
Exemplo n.º 2
0
        //gavdcodeend 02

        //gavdcodebegin 03
        static void SpCsRestReadeOneList(Uri webUri, string userName, string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/lists/getbytitle('NewListRestCs')";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);
                Console.WriteLine(data);
            }
        }
Exemplo n.º 3
0
        //gavdcodeend 04

        //gavdcodebegin 05
        static void SpCsRestDeleteOneList(Uri webUri, string userName, string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/lists/getbytitle('NewListRestCs')";
                IDictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("IF-MATCH", "*");
                headers.Add("X-HTTP-Method", "DELETE");
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Post,
                                              headers, myPayload);
                Console.WriteLine(data);
            }
        }
Exemplo n.º 4
0
        //gavdcodeend 10

        //gavdcodebegin 11
        static void SpCsRestBreakSecurityInheritanceList(Uri webUri, string userName,
                                                         string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/lists/getbytitle('NewListRestCs')/" +
                                     "breakroleinheritance(copyRoleAssignments=false,clearSubscopes=true)";
                IDictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("IF-MATCH", "*");
                headers.Add("X-HTTP-Method", "MERGE");
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Post,
                                              headers, myPayload);
                Console.WriteLine(data);
            }
        }
Exemplo n.º 5
0
        //gavdcodeend 05

        //gavdcodebegin 06
        static void SpCsRestAddOneFieldToList(Uri webUri, string userName,
                                              string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload = new
                {
                    __metadata    = new { type = "SP.Field" },
                    Title         = "MyMultilineField",
                    FieldTypeKind = 3
                };
                string endpointUrl = webUri + "/_api/lists/getbytitle('NewListRestCs')" +
                                     "/fields";
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);
                Console.WriteLine(data);
            }
        }
Exemplo n.º 6
0
 //gavdcodebegin 01
 static void SpCsRestCreateOneList(Uri webUri, string userName, string password)
 {
     using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
     {
         object myPayload = new
         {
             __metadata          = new { type = "SP.List" },
             Title               = "NewListRestCs",
             BaseTemplate        = 100,
             Description         = "Test NewListRestCs",
             AllowContentTypes   = true,
             ContentTypesEnabled = true
         };
         string endpointUrl = webUri + "/_api/web/lists";
         var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);
         Console.WriteLine(data);
     }
 }
Exemplo n.º 7
0
        //gavdcodeend 15

        //gavdcodebegin 16
        static void SpCsRestColumnIndex(Uri webUri, string userName,
                                        string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload = new
                {
                    __metadata = new { type = "SP.Field" },
                    Indexed    = "true"
                };
                string endpointUrl = webUri + "/_api/lists/getbytitle('NewListRestCs')" +
                                     "/fields/getbytitle('MyMultilineField')";
                IDictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("IF-MATCH", "*");
                headers.Add("X-HTTP-Method", "MERGE");
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Post,
                                              headers, myPayload);
                Console.WriteLine(data);
            }
        }