Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to pass parameters to a workflow

Windows Software


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-02-2011
Member
 
Join Date: Jan 2011
Posts: 24
How to pass parameters to a workflow
  

I must establish a workflow for one of my Sharepoint web application. (I say that I totally started there). I chose Visual Studio 2010 to create it because it suits my needs more. However, I have a concern. The launch of the workflow must be performed by receiving an input parameter (ie the identifier of an object from my base). This identifier will certainly recovered from a graphics controller interface of the web site. ("Certainly" because I have not yet done ...). Someone tell me how can I pass a parameter input to a workflow please?

Reply With Quote
  #2  
Old 25-02-2011
Member
 
Join Date: May 2008
Posts: 913
Re: How to pass parameters to a workflow

To do this, there are two ways: through the use of parameters or by the unleashing of events. The parameters are the property of the class that represents the workflow, which can then be used both by the activities in the workflow from the host. To use the events, however, create custom activity to serve as a source of external data and information within the workflow steps. In today's article, we focus only on the use of parameters. We said that to add the parameters, just enter their property in the class that represents the workflow, then, that of taking our first example, this becomes:

workflow1.cs
Code:
public sealed partial class Workflow1 : SequentialWorkflowActivity

{

     private string username;

     public string Username

     {

          get { return username; }

          set { username = value; }

     }

     public Workflow1()

     {

          InitializeComponent();

     }

     private void helloWorldCodeActivity_ExecuteCode(object sender, EventArgs e)

     {

          Console.WriteLine("\nHello {0} !", Username);

     }

}
Reply With Quote
  #3  
Old 25-02-2011
Member
 
Join Date: Nov 2008
Posts: 1,022
Re: How to pass parameters to a workflow

Now when the workflow is instantiated, the properties are the parameters that must be filled with information. What to do? Simple. One of the overloads of CreateWorkflow method (a method used to return an instance of the workflow to be run) in addition to the type of workflow, also provides a generic object type <string, object> Dictionary. Here, this object will contain all key-value pairs useful for passing data to the properties of the workflow, where the key of each pair will be the name of the property to be valued.
Reply With Quote
  #4  
Old 25-02-2011
Member
 
Join Date: Nov 2008
Posts: 1,185
Re: How to pass parameters to a workflow

Here I have provided the code for you by using which you can create the program.cs file that would be helping you to send the parameters to the workflow file.

program.cs
Code:
class Program

{

     static void Main(string[] args)

     {

          using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())

          {

               AutoResetEvent waitHandle = new AutoResetEvent(false);

               workflowRuntime.WorkflowCompleted +=

                         delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};

               workflowRuntime.WorkflowTerminated +=

                         delegate(object sender, WorkflowTerminatedEventArgs e)

               {

                    Console.WriteLine(e.Exception.Message);

                    waitHandle.Set();

               };

               Console.Write("Insert your name: ");

               Dictionary<string, object> parameters = new Dictionary<string, object>();

               parameters.Add("Username", Console.ReadLine());

               Type t = typeof(HelloWorkflow.Workflow1);

               WorkflowInstance instance = workflowRuntime.CreateWorkflow(t, parameters);

               instance.Start();

               waitHandle.WaitOne();

              Console.WriteLine("\n\n");

               Console.WriteLine("Press any key to exit ...");

               Console.Read();

          }

     }

}
Reply With Quote
Reply

  TechArena Community > Software > Windows Software
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to pass parameters to a workflow"
Thread Thread Starter Forum Replies Last Post
Network Diagram - Configure to show Forward Pass/Backward Pass m3lyssa Microsoft Project 9 30-08-2010 04:57 PM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 07:52 PM
Pass Parameters To A Popup in Java Adrina_g Software Development 4 23-02-2010 09:01 PM
How to Pass Parameters to Functions super soaker Software Development 3 31-12-2009 12:16 PM
How to Pass Parameters via URL Paramartha Software Development 4 23-09-2009 06:13 AM


All times are GMT +5.5. The time now is 12:48 AM.