Пример #1
0
        //gavdcodeend 08

        //gavdcodebegin 09
        static void SpCsRestExample01()
        {
            Uri    webUri   = new Uri(ConfigurationManager.AppSettings["spUrl"]);
            string userName = ConfigurationManager.AppSettings["spUserName"];
            string password = ConfigurationManager.AppSettings["spUserPw"];

            using (var client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload   = null;
                string endpointUrl = webUri + "/_api/web/created";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Get, myPayload);

                Console.WriteLine(data);
            }
        }
Пример #2
0
        //gavdcodeend 09

        //gavdcodebegin 10
        static void SpCsRestExample02()
        {
            Uri    webUri   = new Uri(ConfigurationManager.AppSettings["spUrl"]);
            string userName = ConfigurationManager.AppSettings["spUserName"];
            string password = ConfigurationManager.AppSettings["spUserPw"];

            using (var client = new SPHttpClient(webUri, userName, password))
            {
                object myPayload = new
                {
                    __metadata          = new { type = "SP.List" },
                    Title               = "NewTestListRest",
                    BaseTemplate        = 100,
                    Description         = "Test NewListRest",
                    AllowContentTypes   = true,
                    ContentTypesEnabled = true
                };
                string endpointUrl = webUri + "/_api/web/lists";
                var    data        = client.ExecuteJson(endpointUrl, HttpMethod.Post, myPayload);

                Console.WriteLine(data);
            }
        }