可以通过提升申请单的field,然后通过操作SPListItem来操作字段 (workflowProperties.Item 为对应的 SPListItem)
也可以通过直接读取源xml文件来处理.
http://topic.csdn.net/u/20090904/16/2ca275ec-cbe7-4a8c-88d0-d2f7d54f05a1.html
SPFile file = workflowProperties.Item.File;
if (file == null)
return;
// Get the binary data of the file
byte[] xmlFormData = null;
xmlFormData = file.OpenBinary();
// Load the data into an XPathDocument object
XPathDocument ipForm = null;
if (xmlFormData != null)
{
using (MemoryStream ms = new MemoryStream(xmlFormData))
{
ipForm = new XPathDocument(ms);
ms.Close();
}
}
if (ipForm == null)
return;
// Create an XPathNavigator object to navigate the XML
XPathNavigator ipFormNav = ipForm.CreateNavigator();
ipFormNav.MoveToFollowing(XPathNodeType.Element);
XmlNamespaceManager nsManager =
new XmlNamespaceManager(new NameTable());
foreach (KeyValuePair<string, string> ns
in ipFormNav.GetNamespacesInScope(XmlNamespaceScope.All))
{
if (ns.Key == String.Empty)
{
nsManager.AddNamespace("def", ns.Value);
}
else
{
nsManager.AddNamespace(ns.Key, ns.Value);
}
}
// Retrieve the value of the field in the InfoPath form
XPathNavigator nodeNav = ipFormNav.SelectSingleNode(
"//my:field1", nsManager);
string ipFieldValue = string.Empty;
if (nodeNav != null)
{
ipFieldValue = nodeNav.Value;
// Add an item to a list and use the value of the field
// as the title for the new item
if (!String.IsNullOrEmpty(ipFieldValue))
{
using (SPSite site = new SPSite(workflowProperties.SiteId))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.GetList("/Lists/Fruits");
if (list != null)
{
SPListItem item = list.Items.Add();
item["Title"] = ipFieldValue;
item.Update();
}
web.Close();
}
site.Close();
}
}
}