Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
 
 
DZone MVB

Links

Social

SharePoint: Clean code for sequential workflow

I put up here SharePoint workflow code for the next times when Visual Studio screws some workflow up. It is easy for me to take working code here and it is easy for you too. To make code more clean I removed unused namespaces and refactored code so it is a little bit easier to read.

IOCacheCleanupWorkflow.Designer.cs


using Microsoft.SharePoint.WorkflowActions;

 

namespace MyWorkflows

{

    public sealed partial class IOCacheCleanupWorkflow

    {

        #region Designer generated code

        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        [System.Diagnostics.DebuggerNonUserCode]

        private void InitializeComponent()

        {

            this.CanModifyActivities = true;

            System.Workflow.ComponentModel.ActivityBind activitybind2 = new System.Workflow.ComponentModel.ActivityBind();

            System.Workflow.Runtime.CorrelationToken correlationtoken1 = new System.Workflow.Runtime.CorrelationToken();

            System.Workflow.ComponentModel.ActivityBind activitybind1 = new System.Workflow.ComponentModel.ActivityBind();

            this.onWorkflowActivated1 = new Microsoft.SharePoint.WorkflowActions.OnWorkflowActivated();

            activitybind2.Name = "IOCacheCleanupWorkflow";

            activitybind2.Path = "workflowId";

            //

            // onWorkflowActivated1

            //

            correlationtoken1.Name = "correlationToken";

            correlationtoken1.OwnerActivityName = "IOCacheCleanupWorkflow";

            this.onWorkflowActivated1.CorrelationToken = correlationtoken1;

            this.onWorkflowActivated1.EventName = "OnWorkflowActivated";

            this.onWorkflowActivated1.Name = "onWorkflowActivated1";

            activitybind1.Name = "IOCacheCleanupWorkflow";

            activitybind1.Path = "workflowProperties";

            this.onWorkflowActivated1.Invoked += new System.EventHandler<System.Workflow.Activities.ExternalDataEventArgs>(this.onWorkflowActivated1_Invoked);

            this.onWorkflowActivated1.SetBinding(OnWorkflowActivated.WorkflowIdProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind2)));

            this.onWorkflowActivated1.SetBinding(OnWorkflowActivated.WorkflowPropertiesProperty, ((System.Workflow.ComponentModel.ActivityBind)(activitybind1)));

            //

            // IOCacheCleanupWorkflow

            //

            this.Activities.Add(this.onWorkflowActivated1);

            this.Name = "IOCacheCleanupWorkflow";

            this.CanModifyActivities = false;

 

        }

        #endregion

 

        private OnWorkflowActivated onWorkflowActivated1;

 

    }

}


IOCacheCleanupWorkflow.cs


using System;

using System.Workflow.Activities;

using Microsoft.SharePoint.Workflow;

 

namespace MyWorkflows

{

    public sealed partial class IOCacheCleanupWorkflow : SequentialWorkflowActivity

    {

        public IOCacheCleanupWorkflow()

        {

            InitializeComponent();

        }

 

        public Guid workflowId = default(Guid);

        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

 

        private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)

        {

            workflowId = workflowProperties.WorkflowId;

        }

    }

}


If I missed something or if you have suggestions about my “clean” workflow code then please let me know.

Comments

Ramesh said:

Can start your blog from basic of WF with example then it willbe good for new learner also..

# December 17, 2009 1:30 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)