مقدمه
به سری REST SharePoint 2013 خوش آمدید. در مقاله قبلی من، دیدیم که چگونه با استفاده از SharePoint 2013 REST API تعیین کنیم که آیا کاربر در یک سایت وجود دارد یا خیر.
این مقاله نحوه بازیابی انواع گالری لیست در شیرپوینت 2013 را توضیح می دهد.
محیط شیرپوینت 2013 توانایی تعامل از راه دور با سایت های شیرپوینت با استفاده از REST را اضافه می کند. بنابراین می توانید با استفاده از هر فناوری که از قابلیت های استاندارد REST پشتیبانی می کند، با اشیاء شیرپوینت صحبت کنید. به این ترتیب داده های شیرپوینت در هر کجا و همه جا قابل دسترسی است.
لیست نقاط دسترسی REST
فهرستی از نقاط دسترسی است که به شما امکان ورود به نقاط دسترسی گرانول را می دهد.
- سایت
http://server/site/_api/site
- وب
http://server/site/_api/web
- نمایه کاربر
http:// server/site/_api/SP.UserProfiles.PeopleManager
http:// server/site/_api/search را جستجو کنید
- انتشار
http:// server/site/_api/publishing
فهرست نقاط پایانی REST
فهرستی از نقاط پایانی که بیشترین استفاده را در فهرست شیرپوینت دارند در زیر آمده است.
- http://server/site/_api/web/lists
- http://server/site/_api/lists/getbytitle('listname')
- http://server/site/_api/web/lists('guid')
- http://server/site/_api/web/lists/getbytitle('Title')
توجه : کد زیر در محیط آنلاین SP 2013 من تست شده است.
مرحله 1: قبل از نوشتن کد خود، لطفاً مطمئن شوید که مجوز کافی برای دسترسی به درخواستهای بین دامنهای را دارید. بنابراین من به تمام مطالب فهرست شده در زیر اجازه کامل داده ام.
مستاجر |
مجوز کامل |
مجموعه سایت |
مجوز کامل |
وب |
مجوز کامل |
فهرست کنید |
مجوز کامل |
کد قرار دهید
- 'use strict';
- var hostweburl;
- var appweburl;
- // This code runs when the DOM is ready and creates a context object which is
- // needed to use the SharePoint object model
$(document).ready(function () {
- //Get the URI decoded URLs.
- hostweburl =
- decodeURIComponent(
- getQueryStringParameter("SPHostUrl"));
- appweburl =
- decodeURIComponent(
- getQueryStringParameter("SPAppWebUrl"));
- // Resources are in URLs in the form:
- // web_url/_layouts/15/resource
- var scriptbase = hostweburl + "/_layouts/15/";
-
- // Load the js file and continue to load the page with information about the list top level folders.
- // SP.RequestExecutor.js to make cross-domain requests
-
- // Load the js files and continue to the successHandler
- $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
- });
-
- // Function to prepare and issue the request to get
- // SharePoint data
- function execCrossDomainRequest() {
- // executor: The RequestExecutor object
- // Initialize the RequestExecutor with the app web URL.
- var executor = new SP.RequestExecutor(appweburl);
- // Issue the call against the app web.
- // To get the title using REST we can hit the endpoint:
-
- // The response formats the data in the JSON format.
- // The functions successHandler and errorHandler attend the
- // sucess and error events respectively.
- executor.executeAsync(
- {
- url:
-
- appweburl +
-
- "/_api/SP.AppContextSite(@target)/web/ getcatalog(114)? @target='" +
- hostweburl + "'",
- method: "POST",
- data: "{ 'logonName': 'i:0#.f|membership|lakshmansethu@tech716.onmicrosoft.com' }",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
- alert("success: " + JSON.stringify(data));
- error: function (err) {
- alert("error: " + JSON.stringify(err));
- }
- }
- );
- }
- // This function prepares, loads, and then executes a SharePoint query to get
- // the current users information
- //Utilities
- // Retrieve a query string value.
- // For production purposes you may want to use
- // a library to handle the query string.
- function getQueryStringParameter(paramToRetrieve) {
- var params =
- document.URL.split("?")[1].split("&");
- for (var i = 0; i < params.length; i = i + 1) {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve)
- return singleParam[1];
- }
}
مرحله 3: هنگام استقرار، صفحه زیر از شما خواسته می شود. Trust it را فشار دهید و به استقرار ادامه دهید.
Code Walkthrough
A. روش ارسال در REST API
سرویس SharePoint 2013 REST از ارسال دستورات POST که شامل تعاریف شیء به نقاط پایانی هستند که مجموعه ها را نشان می دهند، پشتیبانی می کند. در این مثال، Test List یک لیست شیرپوینت سفارشی است که در آن موارد لیست به روز می شوند.