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. --> <કેન્દ્ર> <ટેબલ> <ટીઆર> <ટીડી>Site Name:</ટીડી> <ટીડી><ઉત્પાદક સામગ્રી પ્રકાર="text" નામ="SiteName" ને="SiteName" /></ટીડી> </ટીઆર> <ટીઆર> <ટીડી colspan="2"> <ઉત્પાદક સામગ્રી પ્રકાર="submit" ને="CreateSiteButton" કિંમત="Create the Site" /> </ટીડી> </ટીઆર> </ટેબલ> </કેન્દ્ર> <લિપિ સ્રોત="../Plugins/jquery-1.11.0.min.js"></લિપિ> <લિપિ> હતી CreateSiteLogicContainer = { createSiteData: { "parameters": { __metadata: { "type": "SP.WebInfoCreationInformation" }, Url: "Paultest1", શીર્ષક: "Paultest1", વર્ણન: "rest-created web by Paul!", ભાષા: 1033, WebTemplate: "sts", UseUniquePermissions: ભૂલ ખવડાવનારું } }, createSite: કાર્ય () { jQuery.support.cors = સાચું; CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").વાલ(); $.ajax({ URL: "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").વાલ() }, માહિતી: JSON.stringify(CreateSiteLogicContainer.createSiteData), success: કાર્ય () { સજાગ("success"); }, ભૂલ: કાર્ય () { સજાગ("error"); } }); }, wireUpForm: કાર્ય () { $("#CreateSiteButton").ક્લિક કરો(કાર્ય () { સજાગ("About to try and create the site."); CreateSiteLogicContainer.createSite(); }); } } CreateSiteLogicContainer.wireUpForm(); </લિપિ>
When successful, you get a JSON packet in response like this:
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.
</અંત>
મારા બ્લોગ પર સબ્સ્ક્રાઇબ કરો.
Twitter પર મને ખાતે અનુસરો http://www.twitter.com/pagalvin