Utilisez la méthode ci-dessous pour mettre à jour les valeurs de formulaire InfoPath de flux de travail .. il est méthode générique ..
Vous devez passer .. FieldName
comme 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)
{
}
}
Merci, Amjad