No one has responded to this discussion for at least a year, so this information may be out of date. If you're looking for information about this topic, please search for a more recent discussion or post a new question.

create list from custom list template using client object model

This question is not answered This question is not answered

on my site I have uploaded a list template based on a document library using document set and content types, when i use the template in creating a new list - the document library is created just fine.

 

when trying to do the same thing programmatically as i have 100's to do based on an existing file structure, the library is created but only as a regular document library - the document set and content types are not present. how exactly are you supposed to do this ? i have read some examples from msdn etc, like so

ListCreationInformation lci = new ListCreationInformation();
Site siteCollection = ctx.Site;
ListTemplateCollection listTemplateList = siteCollection.GetCustomListTemplates(site);
ctx.Load(listTemplateList);
ctx.ExecuteQuery();                  
ListTemplate myTemplate = listTemplateList[0];                   
lci.TemplateFeatureId = myTemplate.FeatureId;
lci.Title = "MrSP's new library";
lci.TemplateType = myTemplate.ListTemplateTypeKind;
lci.QuickLaunchOption = QuickLaunchOptions.On;
List newList = site.Lists.Add(lci);
ctx.ExecuteQuery();

 

now somebody mentions that you have to supply the customschemaxml data as well, but that simply does not make sense - SharePoint already knows what stp file is being used because i'm telling it which custom list template to base the new list on - the customschemaxml data is also probably a few hundred lines of xml! and to get that you have to download teh stp from the site, rename it to cab and extract the manifest file and find the <list....<\list> bit - again that is just not reasonable !

 

am i missing something ? or is that even likely to work ?

any help would be appreciated.

MrSP

All Replies
  • Hi mrSP,

    Perhaps some of the other users might have some experience with this.  You can also look through the Developer’s Resources, if you have not already.

    SharePoint Developer Center

    SharePoint Online for Office 365: Developer Guide

    MSDN: SharePoint Online for Office 365 Developer Guide

    Matt Gill

    Microsoft Office 365 SharePoint Support

  • MrSP, did you find a solution to your coding issue?

    Matt Gill

    Microsoft Office 365 SharePoint Support

  • I have not been able to make it work yet, nor have I been able to find anybody else that has it working...

  • I did find the two links below that seem to be related.  Were these ones that you have already found?

    social.technet.microsoft.com/.../37592b80-f773-4bc5-88d2-c9fd48b2ab00

    social.technet.microsoft.com/.../c018867b-d8c3-438a-b3f9-959b6d42fbcc

    If you are still struggling, you can contact the Developer Support team through 1-800-MICROSOFT.

    Matt Gill

    Microsoft Office 365 SharePoint Support

  • yes, i have read both of these, one prompted me to ask here, as the customshemaxml is about 200-300 lines of xml and is already contained within the stp file that you upload to the server and you tell the server which custom template to use, it seems redundant to have to break open the stp file and retrieve teh xml to add along with your request, i will try the telephone number you supplied :)

    thx

  • You have probably resolved this but If I were you I would write some Powershell code that spits out the list the way you want it....

    Here is an incomplete example in Powershell: (I haven't done any work with templates or document sets but this is how I build lists)

    New-SPList -Url $url -ListTitle " Documents" -ListUrl "Docs" -Description "" -Template "Document Library" -OnQuickLaunch $true

    $SPWeb = Get-SPWeb -Identity $url

    $list = $SPWeb.Lists[" Documents"]

    $list.EnableVersioning = $true

    $list.ForceCheckOut = $true

    $list.Update()

    $list.ContentTypesEnabled = $true

    $list.ContentTypes.Add($SPWeb.AvailableContentTypes["YourContentType"])

    # remove the default content type, readd it, and hide it

    $list.ContentTypes.Delete($list.ContentTypes["Document"].ID)

    $list.ContentTypes.Add($SPWeb.AvailableContentTypes["Document"])

    $list.ContentTypes["Document"].Hidden = $true

    $list.ContentTypes["Document"].Update()

    $list.Update()

    # manipulate default view

    $view = $list.Views[0]

    $view.ViewFields.DeleteAll()

    $view.ViewFields.Add("Type")

    $NameLinkedToDoc = ($list.Fields | where { ($_.Title -eq "Name") -and ($_.AuthoringInfo -eq "(linked to document with edit menu)") })

    $view.ViewFields.Add($NameLinkedToDoc)

    # can add your columns here

    $view.ViewFields.Add($list.Fields["MyCustomField"])

    $view.Update()

    $SPWeb.Dispose()

    New-SPList Code:

    function New-SPList($url, $ListTitle, $ListUrl, $description, $template, $onquicklaunch)

    {

      $SPWeb = Get-SPWeb -Identity $url

      $listTemplate = $SPWeb.ListTemplates[$Template]

      $SPWeb.Lists.Add($ListUrl,$Description,$listTemplate)

      $list = $SPWeb.Lists[$ListUrl]

      $list.Title = $ListTitle

      $list.OnQuickLaunch = $onquicklaunch

      Write-Host "$ListTitle"

      $list.Update()

      $SPWeb.Dispose()

    }

    Good Luck

    0 out of 1 people found this post helpful.

  • I do not believe that sharepoint online can be managed by powershell.

  • Do you use Web services then?  You should be able to do the same thing.

  • you can create new document libraries using the web services, however you cannot pass in a custom template on which to base it on, that works :) hence the post.