Please see the code:
public void AddCountries(){
try
{
SPSite site = new SPSite("http://win-67038mbkel7");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Countries"];
SPListItemCollection listitems = list.Items;
XPathNavigator nav = this.CreateNavigator().
SelectSingleNode("/my:myFields/my:Countries", this.NamespaceManager);// Note: "/my:myFields/my:Countries" => Group Countries
foreach (SPListItem li in listitems)
{
XPathNavigator newNode = null;
newNode = nav.Clone();
newNode.SelectSingleNode("/my:myFields/my:Countries/my:Displayname",
this.NamespaceManager).SetValue(li["Title"].ToString());
newNode.SelectSingleNode("/my:myFields/my:Countries/my:Value",
this.NamespaceManager).SetValue(li["Title"].ToString());
nav.InsertAfter(newNode);
newNode = null;
}
nav.DeleteSelf();
nav = null;
}
catch
{
}
}
No comments:
Post a Comment