如何通过Infopath2010编程方程向Sharepoint List提交数据继(完)

如何通过Infopath2010编程方程向Sharepoint List提交数据  针对上一篇修改了一下,可以直接提交重复表里的数据到列表中,代码实现如下:

public void CTRL1_5_Clicked(object sender, ClickedEventArgs e)
        {
            // 在此处编写代码。
            //using (SPSite site = SPContext.Current.Site)
            using (SPSite site = new SPSite("http://bany-pc"))
            {
                if (site != null)
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        // Turn on AllowUnsafeUpdates on the site
                        web.AllowUnsafeUpdates = true;

                        // Update the SharePoint list based on the values
                        // from the InfoPath form
                        SPList list = web.GetList("/Lists/List3/AllItems.aspx");
                        XPathNavigator root = this.CreateNavigator();                       

                        XPathNodeIterator NodeIter = this.MainDataSource.CreateNavigator().Select("/my:myFields/my:Group/my:Details", this.NamespaceManager);


                        if (list != null)
                        {                           
                            foreach (XPathNavigator myf in NodeIter)
                            {
                                SPListItem item = list.Items.Add();                         

                                item["部门"] = myf.SelectSingleNode("my:部门", NamespaceManager).Value;
                                item["单位"] = myf.SelectSingleNode("my:单位", NamespaceManager).Value;
                                item["姓名"] = myf.SelectSingleNode("my:姓名", NamespaceManager).Value;
                            
                                item.Update();
                            }
                        }

                        // Turn off AllowUnsafeUpdates on the site
                        web.AllowUnsafeUpdates = false;

                        // Close the connection to the site
                        web.Close();
                    }

                    // Close the connection to the site collection
                    site.Close();
                }
            }

image

image

image

转载于:https://www.cnblogs.com/Bany/archive/2013/03/26/2982771.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值