如何通过Infopath2010编程方程向Sharepoint List提交数据

在以下示例中,一个文本字段的 InfoPath 窗体用于将数据提交到名为部门在网站集的根网站中存在自定义 SharePoint 列表和填充从 InfoPath 中的文本框中的数据与此列表中的部门、单位、姓名列。

注意: 用户必须具有正确的权限分配给他们,以便能够将项目添加到 SharePoint 列表。

image

  1. 在 InfoPath 中创建一个新的空白的浏览器兼容的表单模板。
  2. 部门、单位、姓名控件和一个按钮控件添加到 InfoPath 表单模板。

image

  1. 双击该按钮以打开其属性对话框。
  2. 按钮属性对话框中,添加项,更改Add,然后单击编辑表单代码.
  3. Microsoft Visual Studio 工具为应用程序中的项目资源管理器窗口,右键单击项目名称,节点并从上下文菜单中选择添加引用
  4. 添加引用对话框中,从.NET选项卡,在组件列表中选择Windows ® SharePoint ® 服务并单击确定.
  5. FormCode.cs文件中,使用为添加或导入语句Microsoft.SharePoint.
  6. 添加项按钮的事件处理程序中添加下面的C#代码:

  7.             // 在此处编写代码。
                //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;

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

                            if (list != null)
                            {
                                SPListItem item = list.Items.Add();
                                item["部门"] =
                                 MainDataSource.CreateNavigator().SelectSingleNode(
                                  "/my:myFields/my:Group/my:Details/my:部门", NamespaceManager).Value;
                                item["单位"] =
                                 MainDataSource.CreateNavigator().SelectSingleNode(
                                  "/my:myFields/my:Group/my:Details/my:单位", NamespaceManager).Value;
                                item["姓名"] =
                                 MainDataSource.CreateNavigator().SelectSingleNode(
                                  "/my:myFields/my:Group/my:Details/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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值