none
Create document library from custom template via REST API RRS feed

  • Question

  • Hello,

    I've created a custom template for a document library. Now I would like to create a new document library via this template. This is possible via the User Interface.

    But I would like to do it via a SharePoint Workflow and the REST API.

    Is this possible?

    Thursday, January 28, 2016 1:38 PM

Answers

  • Hi,

    It is not possible to create list based on a template from a SharePoint Workflow or from the REST API out of the box. 

    As an alternative, see this guidance from PnP :

    https://channel9.msdn.com/blogs/OfficeDevPnP/Document-and-list-templates-with-app-model

    https://github.com/OfficeDev/PnP-Guidance/blob/master/articles/SharePoint-Add-In-Recipe-list-instance.md

    Using this guidance, you could re-create your template with code and use the Add-in to create the lists.

    Otherwise you could implement a custom web service (Farm solution) inside your SharePoint farm to expose the ability to create list based on a list template.

    See these samples :

    http://www.c-sharpcorner.com/blogs/create-list-from-custom-list-template-programmatically-in-sharepoint122

    https://msdn.microsoft.com/en-us/library/ms464040(v=office.14).aspx

    Regards

    Samuel Levesque | http://sharepointerie.com | Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by Twychopath Friday, January 29, 2016 8:14 AM
    Thursday, January 28, 2016 4:17 PM

All replies

  • Hi,

    It is not possible to create list based on a template from a SharePoint Workflow or from the REST API out of the box. 

    As an alternative, see this guidance from PnP :

    https://channel9.msdn.com/blogs/OfficeDevPnP/Document-and-list-templates-with-app-model

    https://github.com/OfficeDev/PnP-Guidance/blob/master/articles/SharePoint-Add-In-Recipe-list-instance.md

    Using this guidance, you could re-create your template with code and use the Add-in to create the lists.

    Otherwise you could implement a custom web service (Farm solution) inside your SharePoint farm to expose the ability to create list based on a list template.

    See these samples :

    http://www.c-sharpcorner.com/blogs/create-list-from-custom-list-template-programmatically-in-sharepoint122

    https://msdn.microsoft.com/en-us/library/ms464040(v=office.14).aspx

    Regards

    Samuel Levesque | http://sharepointerie.com | Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by Twychopath Friday, January 29, 2016 8:14 AM
    Thursday, January 28, 2016 4:17 PM
  • I don't know about document library, but for SITE, yes this is possible.  You must use the REST api 

    POST  .. _api/web/webinfos/add

    with parameters

           {
    "parameters": {
    "__metadata": {
    "type": "SP.WebInfoCreationInformation"
    },
                    "Url": "john7",
    "Title": "john7",
    "Description": "john7 just testing",
    "Language": 1033,
    "WebTemplate": "{7AEDBA9E-5CCE-4281-85D3-E311DA3A6766}#mytemplate",
    "UseUniquePermissions": false
    }
    }

    and the WebTemplate is the INTERNAL name.  To get the internal name of a CUSTOM template you should call

    GET  ... _api/web/getavailablewebtemplates(1033)

    and look at the "Name" property of the records returned.  


    • Edited by jdhenckel Monday, June 20, 2016 6:05 PM
    Monday, June 20, 2016 6:03 PM
  • I think there is a work around for this if anyone has a similar requirement.

    Here are the steps.

    1. create a document using UI and save it to the library and name it as "new_template_doc" or something like that

    2. if you don't want users to mess with this document, secure it so that no one will delete or update it.

    3. use the REST API "/copyto(strNewUrlbOverWrite)" method to create a new document

    /_api/Web/getfilebyserverrelativeurl('new_template_doc url')/copyto(strnewurl='destination_file_url', boverwrite=true)

    Friday, October 6, 2017 11:56 AM