【问题标题】:How to update the original InfoPath form from within Workflow?如何从 Workflow 中更新原始 InfoPath 表单?
【发布时间】:2011-09-13 01:50:11
【问题描述】:

我创建了一个 InfoPath 表单(例如 Form_ExpenseReport)用于从最终用户收集数据,并创建了一些任务表单(也是 InfoPath 表单,例如 TaskForm_1、TaskForm_2)供我的状态机工作流使用。用户希望在原始 IP 表单 (Form_ExpenseReport) 中查看所有任务表单 (TaskForm_1 & TaskForm_2) 的 cmet。如何从工作流程中更新第一个表单?谁能给我一些建议?

我的环境:

  • MOSS 2007 企业版许可证
  • VS 2008

【问题讨论】:

    标签: workflow infopath


    【解决方案1】:

    使用以下方法从 Workflow 更新 InfoPath 表单中的值。它是通用方法..

    您需要将.. FieldName 传递为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)
            {
    
            }
        }
    

    谢谢, 阿姆贾德

    【讨论】:

      猜你喜欢
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多