65.9K
CodeProject 正在变化。 阅读更多。
Home

MOSS 2007 的 InfoPath 2007 助手

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1投票)

2009 年 2 月 6 日

GPL3
viewsIcon

28608

downloadIcon

166

本文介绍如何获取或设置 InfoPath 表单的值。

引言

最近,我需要从 MOSS 2007 中的表单库中与 InfoPath 2007 表单进行交互。因此,在网上搜索并整理了一些信息后,我创建了一个助手,用于在 C# 中将 InfoPath 表单的组件序列化和反序列化为对象。 想法是使用工作流,我可以捕获或设置表单的任何组件的值。

背景

我们将使用两种方法来操作 InfoPath 的控件。 首先,使用经典的 XML 以及 XPathNavigatorXmlDocument 对象模型。 我们可以使用这种方法获取和设置值。 另一种方法是使用从 InfoPath 表单代码中导出的类,通过 XSD.exe。 对于第一种方法,我参考了:http://www.bizsupportonline.net/infopath2007/programmatically-retrieve-infopath-form-from-sharepoint.htm[^]。 对于另一种方法,我使用了:http://msdn.microsoft.com/en-us/library/bb251017.aspx[^]。

部分代码

我们可以像一个简单的表单一样,在没有 MOSS 2007 的情况下使用此助手

string sStatus = string.Empty;
string sFileSource = string.Empty;
sFileSource = "InfoPathForm.xml";

// Get the value of the field Status from the XML
// representing the InfoPath form
InfoPathHelper.FileName = sFileSource;
sStatus = InfoPathHelper.Value("Status");

// Set the value of the field Status
InfoPathHelper.SetValue("Status", "En Progreso ...");

// We can also get the value of any field by deserializating 
// the InfoPath form with the method DeserializeFile from our Helper
misCampos InfoPathForm = 
  (misCampos)InfoPathHelper.DeserializeFile(sFileSource, typeof(misCampos));
sStatus = InfoPathForm.Status;

或者我们可以将此助手与 MOSS 2007 结合使用,并配合工作流使用

// Go to the specific item (the InfoPath form) in our MOSS
SPSite site = new SPSite("http://miportal.intranet");
SPWeb web = site.AllWebs["Sistemas/Incidentes"];
SPList list = web.Lists["FomulariosInfoPath"];
SPListItem item = list.Items[0];

// Set the filename representing the InfoPath form
InfoPathHelper.SPFileName = item;

// Get the value for the field Status from the form
sStatus = InfoPathHelper.Value("Status");

// Set a value to a field of the form
InfoPathHelper.SetValue("Status", "En Progreso ...");

// Another way to get the value of a field in the InfoPath
// form with deserailization. This only allows getting values
// but no setting any value.
// The object InfoPathFromMoss will have all the fields of the form
misCampos InfoPathFormMoss = 
  (misCampos)InfoPathHelper.DeserializeFile(item.File, typeof(misCampos));
sStatus = InfoPathFormMoss.Status;

项目

该解决方案是在运行 Microsoft Office SharePoint Server 2007 的主机上使用 Visual Studio 2008 创建的。 其中还包括 InfoPath 表单。 祝您编码愉快!

© . All rights reserved.