如何通过Infopath2010编程方程向Sharepoint List提交数据
2013-03-26 13:59
453 查看
在以下示例中,一个文本字段的 InfoPath 窗体用于将数据提交到名为部门在网站集的根网站中存在自定义 SharePoint 列表和填充从 InfoPath 中的文本框中的数据与此列表中的部门、单位、姓名列。
注意: 用户必须具有正确的权限分配给他们,以便能够将项目添加到 SharePoint 列表。
在 InfoPath 中创建一个新的空白的浏览器兼容的表单模板。
将 部门、单位、姓名控件和一个按钮控件添加到 InfoPath 表单模板。
双击该按钮以打开其属性对话框。
在按钮属性对话框中,添加项,更改Add,然后单击编辑表单代码.
在Microsoft Visual Studio 工具为应用程序中的项目资源管理器窗口,右键单击项目名称,节点并从上下文菜单中选择添加引用。
添加引用对话框中,从.NET选项卡,在组件列表中选择Windows ® SharePoint ® 服务并单击确定.
在FormCode.cs文件中,使用为添加或导入语句Microsoft.SharePoint.
向添加项按钮的事件处理程序中添加下面的C#代码:
// 在此处编写代码。
//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");
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();
}
}
注意: 用户必须具有正确的权限分配给他们,以便能够将项目添加到 SharePoint 列表。
在 InfoPath 中创建一个新的空白的浏览器兼容的表单模板。
将 部门、单位、姓名控件和一个按钮控件添加到 InfoPath 表单模板。
双击该按钮以打开其属性对话框。
在按钮属性对话框中,添加项,更改Add,然后单击编辑表单代码.
在Microsoft Visual Studio 工具为应用程序中的项目资源管理器窗口,右键单击项目名称,节点并从上下文菜单中选择添加引用。
添加引用对话框中,从.NET选项卡,在组件列表中选择Windows ® SharePoint ® 服务并单击确定.
在FormCode.cs文件中,使用为添加或导入语句Microsoft.SharePoint.
向添加项按钮的事件处理程序中添加下面的C#代码:
// 在此处编写代码。
//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");
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();
}
}
相关文章推荐
- 如何通过Infopath2010编程方程向Sharepoint List提交数据继(完)
- 如何从Excel中把数据导入到SharePoint List(Import Excel data to SharePoint List)
- 如何从Excel中把数据导入到SharePoint List(Import Excel data to SharePoint List)
- 如何从Excel中把数据导入到SharePoint List(Import Excel data to SharePoint List)
- 如何从SharePoint Content DB中查询List数据
- 如何从SharePoint Content DB中查询List数据
- 如何使用dac获取sharepoint list的数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- 如何通过Retrofit提交Json格式数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- SharePoint 2013 BI之report service 常用功能 连接到SharePoint List 数据源
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- Import SpreedSheet 从Excel中导入数据生成SharePoint List
- Sharepoint学习笔记---如何找到SharePoint List的Template ID
- Excel数据导入到Sharepoint List
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- SharePoint 2007 系列(11) 导入Excel数据到SharePoint List
- 如何使用CAML 批量更新SharePoint List
- 在MVC中如何在使用 MicrosoftMvcValidation验证的前提下使用 jQuery.Ajax 提交数据的时候检查验证是否通过