예제 #1
0
        //gavdcodeend 01

        //gavdcodebegin 02
        static void SpCsRestCreateOneSiteCollection(Uri webBaseUri, string userName,
                                                    string password)
        {
            using (SPHttpClient client = new SPHttpClient(webBaseUri, userName, password))
            {
                string myPayload =
                    "{" +
                    "'request':  {" +
                    "'__metadata': { 'type':" +
                    "        'Microsoft.SharePoint.Portal.SPSiteCreationRequest' }," +
                    "'Title': 'NewSiteCollectionModernCsRest02'," +
                    "'Lcid': 1033," +
                    "'Description': ''," +
                    "'Classification': ''," +
                    "'ShareByEmailEnabled': false," +
                    "'SiteDesignId': '00000000-0000-0000-0000-000000000000'," +
                    "'Url': '" + webBaseUri + "/sites/NewSiteCollectionModernCsRest02'," +
                    "'WebTemplate': 'SITEPAGEPUBLISHING#0'," +
                    "'WebTemplateExtensionId': '00000000-0000-0000-0000-000000000000'" +
                    "}}";
                string endpointUrl = webBaseUri + "_api/SPSiteManager/create";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #2
0
        //gavdcodeend 14

        //gavdcodebegin 15
        static void SpCsRestDeleteUserFromSecurityRoleInWeb(Uri webUri,
                                                            string userName, string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            // Find the User
            int userId = 0;

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_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(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web/" +
                                     "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);
            }
        }
예제 #3
0
 //gavdcodebegin 01
 static void SpCsRestCreateOneCommunicationSiteCollection(Uri webBaseUri,
                                                          string userName, string password)
 {
     using (SPHttpClient client = new SPHttpClient(webBaseUri, userName, password))
     {
         object myPayload = new
         {
             __metadata = new
             {
                 type =
                     "SP.Publishing.CommunicationSiteCreationRequest"
             },
             Title       = "NewSiteCollectionModernCsRest",
             Description = "NewSiteCollectionModernCsRest Description",
             AllowFileSharingForGuestUsers = false,
             SiteDesignId = "6142d2a0-63a5-4ba0-aede-d9fefca2c767",
             Url          = webBaseUri + "sites/NewSiteCollectionModernCsRest",
             lcid         = 1033
         };
         string endpointUrl = webBaseUri +
                              "_api/sitepages/communicationsite/create";
         var data = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);
         Console.WriteLine(data);
     }
 }
예제 #4
0
        //gavdcodeend 04

        //gavdcodebegin 05
        static void SpCsRestReadAllWebsInSiteCollection(Uri webUri, string userName,
                                                        string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/web/webs";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #5
0
        //gavdcodeend 03

        //gavdcodebegin 04
        static void SpCsRestReadAllSiteCollections(Uri webBaseUri, string userName,
                                                   string password)
        {
            using (SPHttpClient client = new SPHttpClient(webBaseUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webBaseUri +
                                     "/_api/search/query?querytext='contentclass:sts_site'";
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #6
0
        //gavdcodeend 11

        //gavdcodebegin 12
        static void SpCsRestResetSecurityInheritanceWeb(Uri webUri, string userName,
                                                        string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web/resetroleinheritance";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #7
0
        //gavdcodeend 07

        //gavdcodebegin 08
        static void SpCsRestGetRoleDefinitionsWeb(Uri webUri, string userName,
                                                  string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web/roledefinitions";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #8
0
        //gavdcodeend 09

        //gavdcodebegin 10
        static void SpCsRestFindOtherUserPermissionsWeb(Uri webUri, string userName,
                                                        string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web/" +
                                     "getusereffectivepermissions(@v)?@v=" +
                                     "'i%3A0%23.f%7Cmembership%7C" + userName + "'";
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #9
0
        //gavdcodeend 08

        //gavdcodebegin 09
        static void SpCsRestFindUserPermissionsWeb(Uri webUri, string userName,
                                                   string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web/" +
                                     "doesuserhavepermissions(@v)?@v=" +
                                     "{'High':'2147483647', 'Low':'4294967295'}";
                var data = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #10
0
        //gavdcodeend 12

        //gavdcodebegin 13
        static void SpCsRestAddUserToSecurityRoleInWeb(Uri webUri, string userName,
                                                       string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            // Find the User
            int userId = 0;

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_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);
            }

            // Find the RoleDefinitions
            int roleId = 0;

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

            // Add the User in the RoleDefinion to the List
            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web/lists/getbytitle" +
                                     "('TestList')/items(17)/roleassignments/addroleassignment" +
                                     "(principalid=" + userId + ",roledefid=" + roleId + ")";
                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);
            }
        }
예제 #11
0
        //gavdcodeend 06

        //gavdcodebegin 07
        static void SpCsRestDeleteOneWebFromSiteCollection(Uri webUri, string userName,
                                                           string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web";
                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);
            }
        }
예제 #12
0
        //gavdcodeend 10

        //gavdcodebegin 11
        static void SpCsRestBreakSecurityInheritanceWeb(Uri webUri, string userName,
                                                        string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = subWebUri + "/_api/web" +
                                     "/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);
            }
        }
예제 #13
0
        //gavdcodeend 02

        //gavdcodebegin 03
        static void SpCsRestCreateOneWebInSiteCollection(Uri webUri, string userName,
                                                         string password)
        {
            using (SPHttpClient client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload = new
                {
                    __metadata  = new { type = "SP.WebCreationInformation" },
                    Title       = "NewWebSiteModernCsRest",
                    Description = "NewWebSiteModernCsRest Description",
                    Url         = "NewWebSiteModernCsRest",
                    UseSamePermissionsAsParentSite = true,
                    WebTemplate = "STS#3"
                };
                string endpointUrl = webUri + "/_api/web/webinfos/add";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);
                Console.WriteLine(data);
            }
        }
예제 #14
0
        //gavdcodeend 05

        //gavdcodebegin 06
        static void SpCsRestUpdateOneWeb(Uri webUri, string userName,
                                         string password)
        {
            Uri subWebUri = new Uri(webUri + "/NewWebSiteModernCsRest");

            using (SPHttpClient client = new SPHttpClient(subWebUri, userName, password))
            {
                object myPayload = new
                {
                    __metadata  = new { type = "SP.Web" },
                    Description = "NewWebSiteModernCsRest Description Updated"
                };
                string endpointUrl = subWebUri + "/_api/web";
                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);
            }
        }