Murali Kris

Murali Kris

  • 1.5k
  • 254
  • 48.4k

How to Create s SharePoint list with List SchemaXML

Oct 9 2018 9:49 AM
Hi ,
 
I would like to create a sharePoint list with List SchemaXML file.
 
as we know SchemaXML have list meta data(fields, Views, content types, Forms etc).
list.SchemaXML returning schemaxml file. and also am formating in to xml format with help of Formatting.Indented. till here fine. means i am getting proper list schemaXML file.
Now i want to create same new list on my target site with schemaXML.
 
when i am trying to create i am getting error like "Additional information: Cannot complete this action".
 
it seems like there is no error but dont know what is the wrong here.
 
var data = list.SchemaXML;
XmlDocument doc = new XmlDocument();
doc.LoadXml(data.ToString()); // data will return ShemaXML
string st = doc.InnerXml;
//list properties
var title = list.Title;
var des = list.Description;
var basetype = list.BaseTemplate;
//var templatetype = int.Parse(list.BaseType.ToString());
var gelinst = list.BaseType;
string url = "mynewtestxml";
var featureid = list.TemplateFeatureId;
//Create new list
ListCreationInformation listcreate = new ListCreationInformation();
listcreate.Title = "mynewtestxml";
listcreate.Description = "";
listcreate.TemplateType = basetype;//templatetype;//(int)ListTemplateType.GenericList;
listcreate.Url = url;
listcreate.TemplateFeatureId = featureid;
listcreate.CustomSchemaXml = st;
List newlist = ctx.Web.Lists.Add(listcreate);
ctx.Load(newlist);
ctx.ExecuteQuery(); error here like "Cannot complete this action"
 
kindly help me what is the error here.
 
Here i also want to know is the above script create a new list with all meta data properties means the source list structure on target. if no kindly what is the best way to create a new list with source list structure(apart from list Template Import and Export). Since i should not upload list template to create a new list with source list structure.
 
Thanks In Advance.

Answers (5)