使用编程的方式来启动SharePoint的工作流 并传入参数
2011-10-13 08:33
459 查看
(1) Define one class with properties
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.
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.
http://www.sharepointkings.com/2008/09/how-to-pass-parameters-to-workflow.html
/article/7036206.html
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 triggers private 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
/article/7036206.html
相关文章推荐
- 使用编程的方式来启动SharePoint的工作流
- 使用编程的方式来启动SharePoint的工作流
- 使用编程的方式来启动SharePoint的工作流
- JavaScript函数参数使用带参数名的方式赋值传入的方法
- 前后端分离的j2ee的web项目,使用vue方式,即{{}}方式批量传入前端参数,遇到一个一个问题,页面上一开始有{{}},怎么处理?
- @Param注解在mybatis中的使用以及传入参数的几种方式(转)
- Sharepoint 复制备份系列--使用编程方式复制列表2(Copy a SharePoint List or site ,web Programmatically)
- Windows Service 使用参数安装DEMO,可使用控制台启动方式进行调试,服务安装完后立即启动
- Sharepoint 复制备份系列--使用编程方式复制列表1(Copy a SharePoint List Programmatically)
- 基于visual c++之windows核心编程代码分析(52)使用WMI 获取进程启动参数
- 基于visual c++之windows核心编程代码分析(52)使用WMI 获取进程启动参数
- Android编程实现启动另外的APP及传递参数的方法
- 使用 SharePoint 2007 进行安全性编程
- js脚本捕获页面 GET 方式请求的参数?其实直接使用 window.location.search 获得
- archlinux下安装btrfs gpt 使用bios_grub方式启动
- WF4.0 工作流设计器 传入参数问题记录?
- HOW TO:使用 Visual C# .NET 在 ADO.NET 中以编程方式构建连接字符串
- JS中使用apply、bind实现为函数或者类传入动态个数的参数
- PerformClick 方法使用 以编程方式调用按钮的 Click 事件 (Visual C#)
- Mybatis传入多个参数处理方式