How to update the original InfoPath form from within Workflow?
I have created an InfoPath form (e.g. Form_ExpenseReport) for collect data from end users, and a number of task forms (also InfoPath form, e.g. TaskForm_1, TaskForm_2) for my state machine workflow use. The users want to see all the comments of Task forms (TaskForm_1 & TaskForm_2) in the original IP form (Form_ExpenseReport). How can I update the first form from within workflow? Can anybody give me some tips?
My environment:
- MOSS 2007开发者_如何学JAVA Enterprise license
- VS 2008
Use the below method to update the values in InfoPath form from Workflow.. it is generic method..
You need to pass .. FieldName
as xpath (/myfields/my:txtcomments",your values)
public void SetFormFieldvalue(string FieldName, string FieldValue)
{
SPFile file = workflowProperties.Item.File;
string strLabel = string.Empty;
try
{
XmlDocument modifyEmpXMlDoc = new XmlDocument();
using (MemoryStream memorySream = new MemoryStream(file.OpenBinary()))
{
modifyEmpXMlDoc.PreserveWhitespace = true;
modifyEmpXMlDoc.Load(memorySream);
memorySream.Close();
}
if (modifyEmpXMlDoc == null)
return;
XPathNavigator modifyEmpFormNav = modifyEmpXMlDoc.CreateNavigator();
modifyEmpFormNav.MoveToFollowing(XPathNodeType.Element);
XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());
foreach (KeyValuePair<string, string> nameSpace
in modifyEmpFormNav.GetNamespacesInScope(XmlNamespaceScope.All))
{
if (nameSpace.Key == String.Empty)
{
nsManager.AddNamespace("def", nameSpace.Value);
}
else
{
nsManager.AddNamespace(nameSpace.Key, nameSpace.Value);
}
}
// Change the value of the InfoPath form field
modifyEmpXMlDoc.SelectSingleNode(FieldName,
nsManager).InnerText = FieldValue;
// Save the bytes of the XML document as the contents
// of the SPFile object that represents the InfoPath form
file.SaveBinary(Encoding.UTF8.GetBytes(modifyEmpXMlDoc.OuterXml));
// Save the changes made to the SPFile object
file.Update();
}
catch (Exception ex)
{
}
}
Thanks, Amjad
精彩评论