Hello fellow Stackers!
I have a serious query that has been bugging me for weeks:
I'm developing a tool that takes data from a Sharepoint list, filters it, matches it to another list template, and plugs the matched data into the appropriate columns. This all seems fine.
The problem comes when I am creating a new list for the filtered/matched data to fall into. I create a new list based on the current DateTime and a simple naming string.
XmlNode newFields = null;
XmlNode deleteFields = null;
XmlNode updateFields = null;
XmlNode propertyFields = null;
XmlDocument xmlDoc = null;
xmlDoc = new XmlDocument();
_spService.Credentials = new NetworkCredential(user, pw, domain);
_spService.Url = "http://ift.tt/1pTIAFf";
_spService.AddListFromFeature(currentList, "", new Guid("00BFEA71-DE22-43B2-A848-C05709900100"), 100);
The problem comes when I try to update the column names to match the output columns in my data set:
XmlNode ndList = _spService.GetList(currentList);
XmlNode ndVersion = ndList.Attributes["Version"];
newFields = xmlDoc.CreateNode(XmlNodeType.Element, "Fields", "");
string temp = "";
int x = 1;
foreach (OutputItem o in list)
{
temp += "<Method ID='"+ x++ +"'>";
temp += "<Field Type='Text' DisplayName='" + o.ColumnName + "' Name='" + o.ColumnName + "' ReadOnly='FALSE' Required='FALSE' ShowField='TRUE' Description='description' />";
temp += "</Method>";
}
newFields.InnerXml = temp;
deleteFields = xmlDoc.CreateNode(XmlNodeType.Element, "Fields", "");
deleteFields.InnerXml = "";
updateFields = xmlDoc.CreateNode(XmlNodeType.Element, "Fields", "");
updateFields.InnerXml = "";
propertyFields = xmlDoc.CreateNode(XmlNodeType.Element, "List", "");
XmlAttribute titleAttrib = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "Title", "");
titleAttrib.Value = currentList;
XmlAttribute descAttrib = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "Description", "");
descAttrib.Value = "New source file";
propertyFields.Attributes.Append(titleAttrib);
propertyFields.Attributes.Append(descAttrib);
deleteFields.InnerXml = "<Method ID='" + x + "'><Field Name='Title'/></Method>";
_spService.UpdateList(currentList, propertyFields, newFields: newFields, updateFields: updateFields, deleteFields: deleteFields, listVersion: "1.0.0.0");
The last line is where it breaks, everytime claiming that "'None' is an invalid XmlNodeType. Line 1, position 11." As you can see I don't need all the fields so I've tried "nulling" the ones I don't need like so:
_spService.UpdateList(currentList, propertyFields, newFields: newFields, updateFields: null, deleteFields: deleteFields, listVersion: "1.0.0.0");
However this always returns "Input string was not in a correct format." So I've researched both of these and I can't find anything that shares a similar problem.
You may also have noticed that when I created the list I included a Feature ID, this doesn't appear to work. The ID included is a template that all these new lists and their columns are based on. So if you could show me how that works then I could skip all this "UpdateList" hullabaloo.
Thanks for your help,
Adurnari
P.S.: I'm restricted against using Sharepoint Designer, so any easy fix that might happen that way, can't.

0 commentaires:
Enregistrer un commentaire