none
How to use CustomSchemaXml to create List in CSOM RRS feed

  • Question

  • How to create a list using CustomSchemaXml property for creating List in Client Object Model. This property is present in ListCreationInformation class. There must be a significance to this property.

    Has anybody created list using this property?

    Wednesday, November 6, 2013 1:47 AM

Answers

All replies

  • In the case of creating an external list the CustomSchemalXml is used to create List Views and Forms. Not much documentation in this.

    Blog |SharePoint Field Notes Dev Tool | SPFastDeploy

    Thursday, November 7, 2013 12:40 AM
  • Hi,

    If you just want to create SharePoint List use Client Side Object Mode, the following code snippet for your reference:

    using(ClientContext ctx = new ClientContext("http://site/"))
    {
        ListTemplateCollection ltc = ctx.Web.ListTemplates;
        ctx.Load(ltc);
        ctx.ExecuteQuery();
        ListTemplate listTemplate=null;
        foreach (ListTemplate lt in ltc)
        {
            if(lt.Name.Equals("Custom List"))
            {
                listTemplate = lt;
            }
        }
                                        
        ListCreationInformation lc = new ListCreationInformation();
        lc.Title = "SimpleList";
        lc.TemplateType = listTemplate.ListTemplateTypeKind;
        lc.Description = "Test";
        List newList = ctx.Web.Lists.Add(lc);
    
        ctx.ExecuteQuery();
    }
    

    We cannot create a List using the custom template in Client Object Model. Try creating a custom list definition, and then create list based on this definition.

    Here is a similar thread for you to take a look at:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/c018867b-d8c3-438a-b3f9-959b6d42fbcc/create-list-using-custom-template-using-the-client-object-model

    Best Regards


    Dennis Guo
    TechNet Community Support

    Thursday, November 7, 2013 3:34 AM
    Moderator
  • In your code, what is "Custom List"? Is it a list which is already present?
    Thursday, November 7, 2013 7:45 PM
  • Hi,

    The 'Custom List' is a SharePoint OOB List template. The value of this template type is 100.

    More information:

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx

    Best Regards


    Dennis Guo
    TechNet Community Support

    Friday, November 8, 2013 1:15 AM
    Moderator
  • Hi All,

    I am creating a list with CSOM with Template type ListTemplateType.GenericList, I also want to create some custom fields and ContentTypes in the list.

    So how can I use the CustomSchemaXml to define the list schema, so that the list is created with my defined fields, ContentTypes and Views.

    Will the CustomSchemaXml have the same XML that we use in Schema.xml when creating a list.

    Please suggest. Thanks in advance.


    Himanshu Nigam

    Tuesday, June 24, 2014 4:52 AM
  • It is not clear whether this property works -- understanding you faced this issue over a year ago, have you resolved this?? Facing the same issue right now.

    Alex Talarico

    Monday, February 2, 2015 4:29 PM
  • Yes, CustomSchemaXml works fine.

    The XML structure is not obvious but Visual Studio's generated XML works as-is so that's an easy way to start out. Add a list to a SharePoint project and then grab the schema.xml file.

    You also need to provide the feature ID of the list template.

    I posted a full PowerShell remote provisioning example, with XML, here.

    • Edited by martindr Tuesday, February 10, 2015 6:50 PM
    Tuesday, February 10, 2015 4:14 PM
  • Hi Martindr,

    Can you please help me.

    1. how to get Listschema.xml file using programattically. Tryed with below powershell CSOM code but no luck generating file with 0KB(blank.xml)  and error is (Cannot find an overload for "Load" and the argument count: "1"). Can you please suggest me to how to get listschema.xml

    $web = $spCtx.Web
    $listnow =$web.Lists.GetByTitle("listtestnow")
    #$lists = $spCtx.web.Lists
    $spCtx.Load($listnow)
    $spCtx.ExecuteQuery() 
    $list.SchemaXML
    $spCtx.Load($list.SchemaXML)
    $spCtx.ExecuteQuery()
    Add-Content -Path "D:\listschema.xml" -Value $list.SchemaXML

    kmk

    Monday, October 1, 2018 11:56 AM