使用编程的方式来启动SharePoint的工作流 并传入参数
来源:互联网 发布:深圳社保积分怎么算法 编辑:程序博客网 时间:2024/06/06 17:55
(1) Define one class with properties
using System.Xml.Serialization;using System.Xml;using System.IO;[Serializable()]public class WorkflowParameters{private string _ZipCode = default(string);public string ZipCode{get { return _ZipCode; }set { _ZipCode = value; }}private string _CountryCode = default(string);public string CountryCode{get { return _CountryCode; }set { _CountryCode = value; }}public string getInitXmlString(WorkflowParameters objParams){WorkflowParameters data = new WorkflowParameters();data._CountryCode = objParams._CountryCode;data._ZipCode = objParams._ZipCode;using (MemoryStream stream = new MemoryStream()){XmlSerializer serializer = new XmlSerializer(typeof(WorkflowParameters));serializer.Serialize(stream, data);stream.Position = 0;byte[] bytes = new byte[stream.Length];stream.Read(bytes, 0, bytes.Length);return Encoding.UTF8.GetString(bytes);}}}
Here as you can see we have defined two properties ZipCode and CountryCode as an example. you make paramters accordingly to your need.
(2) Next, step is to dynamically execute the workflow, for this code you can refer post 1. I am working with event handler of a list, so here is a code which demonstrate the idea about executing workflow from event handler. change this code according to the code where you writing it.
SPWorkflowManager objWorkflowManager = null;SPWorkflowAssociationCollection objWorkflowAssociationCollection = null;SPListItem item = properties.ListItem;objWorkflowManager = item.Web.Site.WorkflowManager;objWorkflowAssociationCollection = item.ParentList.WorkflowAssociations;foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection){//Find the GUID for the workflow association WorkflowParameters objParams = new WorkflowParameters();objParams.ZipCode = "12345";objParams.CountryCode = "USA";string strSerializedParams = objParams.getInitXmlString(objParams);objWorkflowAssociation.AssociationData = strSerializedParams;if (String.Compare(objWorkflowAssociation.BaseId.ToString("B"),"{workflow_ID}", true) == 0){objWorkflowManager.StartWorkflow(item, objWorkflowAssociation,objWorkflowAssociation.AssociationData, true);}}
As you can see here we have created an object of our previous defined class which is serializable. we set the properties and passed it to a public method of the same class and then we get the string as in the form of XML, which is then assigned to the AssociationData of workflowassociation which is passed to a workflow.
(3) Now you need to retrive these data in the workflow. Now you have to go to a Workflow Code. Let us assume that we fetch these data in Workflow Invoke Activity.
//Assume that this is the activity that executes when workflow triggersprivate void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e){//Fetch with workflow properties InitiationData property which gets the//Parameters passed to it.string strParametrsPassed = workflowProperties.InitiationData;XmlSerializer xs = new XmlSerializer(typeof(WorkflowParameters));XmlTextReader xtr = new XmlTextReader(new System.IO.StringReader(workflowProperties.InitiationData));WorkflowParameters init = (WorkflowParameters)xs.Deserialize(xtr);string zipcode = init.ZipCode;//Now this string returns you string in XML format which looks like this,//<?xml version="1.0"?>//<WorkflowParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-//instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">// <ZipCode>12345</ZipCode>// <CountryCode>USA</CountryCode>//</WorkflowParameters>}
http://www.sharepointkings.com/2008/09/how-to-pass-parameters-to-workflow.html
http://www.cnblogs.com/fanwenxuan/archive/2011/06/09/2076829.html
- 使用编程的方式来启动SharePoint的工作流 并传入参数
- 使用编程的方式来启动SharePoint的工作流
- C:LINUX如何来使用传入的参数
- Linux下使用getopt函数来获取传入的参数
- oozie 编程方式的工作流
- SharePoint 工作流不能自动启动的常见原因
- C#中通过引用来传递参数?有几种?区别?例?(传入参数A,并返回操作后的A)?
- Java使用MyBatis传入参数的问题
- Oracle存储过程传入类似java中list、数组类型的参数并使用
- SharePoint 2010 工作流解决方案:创建带有关联窗体和启动窗体的工作流
- SharePoint Designer工作流的扩展
- SharePoint 工作流无法启动?
- python参数的传入 * ,**
- uboot传入的linux启动参数解析。命令行
- uboot传入的linux启动参数解析。命令行
- 用CommandLine可以传入程序启动的参数
- uboot传入的linux启动参数解析----命令行
- PHP命令行脚本接收传入参数的三种方式
- 如何在vs2008中加入flash
- CSS 动画指南: 原理和实战
- onTouchEvent dispatchTouchEvent interceptTouchEvnet 之间的传递
- SCI影响因子 - 首页
- unidac连接ORACLE免装客户端驱动
- 使用编程的方式来启动SharePoint的工作流 并传入参数
- Linux各种文件压缩命令总结
- 重构之前
- Dataguard逻辑备库创建
- LRU
- Dataguard物理备库创建
- [Repaste] Why Dart is not the language of the future
- .Net正则的小记——都是粗心大意惹的祸
- 1的个数