Friday, 7 September 2012

Data Binding with SharePoint 2010 list in InfoPath 2010

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