دسترسی سریع و آسان: ایجاد یک REST شیرپوینت سایت با استفاده از

There are a lot of resources around that show how to do this, but I couldn’t find a comprehensive go-to link, so here we are.

You can create a SharePoint site using the REST API.  Here’s a fully baked example:

<!--
    SiteRequestForm.html: Collect information and create a site for the user.
-->

<مرکز>
<جدول>
    <TR>
        <فلش>Site Name:</فلش>
        <فلش><ورودی نوع="text" نام="SiteName" شناسایی="SiteName" /></فلش>
    </TR>
    <TR>
        <فلش colspan="2">
            <ورودی نوع="submit" شناسایی="CreateSiteButton" ارزش="Create the Site" />
        </فلش>
    </TR>
</جدول>
</مرکز>

<خط src="../Plugins/jquery-1.11.0.min.js"></خط>

<خط>
ور CreateSiteLogicContainer = {

    createSiteData: {
            "parameters": {
                __metadata: { "type": "SP.WebInfoCreationInformation" },
                آدرس: "Paultest1",
                عنوان: "Paultest1",
                شرح: "rest-created web by Paul!",
                زبان: 1033,
                WebTemplate: "sts",
                UseUniquePermissions: غلط
            }
    },

    createSite: تابع () {

        jQuery.support.cors = درست;

        CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").وال();
        
        $.ajax({
            آدرس: "https://bigapplesharepoint.sharepoint.com/NBAIADev/_api/web/webinfos/add",
            روش: "POST",

            headers: {
                "Accept": "application/json; odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").وال()
            },

            data: JSON.stringify(CreateSiteLogicContainer.createSiteData),

            success: تابع () { هوشیار("success"); },
            خطا: تابع () { هوشیار("error"); }

        });
    },

    wireUpForm: تابع () {
        $("#CreateSiteButton").click(تابع () {
            هوشیار("About to try and create the site.");
            CreateSiteLogicContainer.createSite();
        });
    }


}

CreateSiteLogicContainer.wireUpForm();

</خط>

When successful, you get a JSON packet in response like this:

image

My key thoughts and learnings from this include:

  • This approach uses jQuery.  در مورد من, my jQuery library is located in “../plugins.”  You’ll want to change that to point to your favorite JQ location.
  • You can copy and paste that whole snippet into a Content Editor Web Part on a page and it should work just fine.  You’ll want to change the end point of the API call and make sure you reference JQ correctly.
  • The URL is relative to your API’s endpoint.  در مورد من, it’s creating sub-sites underneath https://bigapplesharepoint.com
  • You don’t need to provide a content-length. Some blog posts and MSDN document implies that you do, but happened for me automatically, which I assume is being handled by the $.ajax call itself.
  • This line is required in order to avoid a “forbidden” response: "X-RequestDigest": $("#__REQUESTDIGEST").وال().  There are other ways to do it, but this is pretty nice.  I have lost the link to blog that provided this shortcut.  H/T to you, mysterious blogger!

Good luck and hope this helps someone out.

</پایان>

undefinedمشترک شدن در وبلاگ من.

من در توییتر در http://www.twitter.com/pagalvin

پاسخ

آدرس ایمیل شما منتشر نخواهد شد. بخشهای موردنیاز علامتگذاری شدهاند *