Creating an If, Elseif, Else condition in Workflow .Net 4.0

Posted on 2011-04-29
Last Modified: 2012-05-11
I'm new to windows workflow foundation and I'm trying to create a new flowchart item that works just like a FlowDecision but has a third branch that has a test for null. This is the login in C# I'm trying to create:

If (condition=="Y") then

ElseIf (condition=="N") then

Else (this is null)

Ideally I would like a generic item that is added to my toolbox that I can drag and drop that will create the 3 branches.


Question by:jgoodale
    LVL 1

    Expert Comment

    try this

    if(item == condition)
       //code here
    else if (item == condition2)
     //code here
    //code here

    If you have more a simple if then else, a switch/case statement would be better

      case "condition1":
        item = "1";
     case "condition2":
     case "condition3"

    Here is an example I used based on the day selected from a calendar to format the date in objects based on the day of the week (the date is on Oracle date format)

    protected void DefaultDay()
             * Puts default work week in txtWeekBeginning and txtWeekEnd

            DateTime today;
            String DayofWeek;
            String strSelectedDay;

            today = System.DateTime.Today;
            txtSelectedDay.Text = today.DayOfWeek.ToString();
            strSelectedDay = txtSelectedDay.Text;

            switch (strSelectedDay)
                case "Sunday":
                    txtWeekBeginning.Text = today.ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.AddDays(6).ToString("dd-MMM-yyyy");
                case "Monday":
                    txtWeekBeginning.Text = today.AddDays(-1).ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.AddDays(5).ToString("dd-MMM-yyyy");
                case "Tuesday":
                    txtWeekBeginning.Text = today.AddDays(-2).ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.AddDays(4).ToString("dd-MMM-yyyy");
                case "Wednesday":
                    txtWeekBeginning.Text = today.AddDays(-3).ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.AddDays(3).ToString("dd-MMM-yyyy");
                case "Thursday":
                    txtWeekBeginning.Text = today.AddDays(-4).ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.AddDays(2).ToString("dd-MMM-yyyy");
                case "Friday":
                    txtWeekBeginning.Text = today.AddDays(-5).ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.AddDays(1).ToString("dd-MMM-yyyy");
                case "Saturday":
                    txtWeekBeginning.Text = today.AddDays(-6).ToString("dd-MMM-yyyy");
                    txtWeekEnd.Text = today.ToString("dd-MMM-yyyy");



    Author Comment

    twhaight: I'm looking for a solution using the workflow objects in .Net 4.0. I have my code working using flowswitches but I'm not sure if this is the right solution for what I want.. I will paste some code in my next post.
    LVL 8

    Accepted Solution

    I think I understand where you are going as i have had spend day and night thinking about this solution where in  I can have multiple branch from a activitiy
    This is by default not possible in WF4 as i tried all ways to override all the classes that .net expose from flownode to flowdecison but all in vain coz they are protected internal and cannot be overridden

    Then offlate i came to know that WF4 patch has been released with some thing called statemachine
    which will allow you to manipulate different states your systems is in

    if you search on this over the net you would get lots of forum where this question have been asked but not leading anywhere..

    This link has video tutorial to start with
    you have to install Vs2010 SP1 and one more patch to have start with (more info can be found in the video)
    you can refer the below link to go with statemachine


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now