Custom Site Workflow in SharePoint

This article explains Site Work Flow development step-by-step.

What a Site Workflow is

Site Workflows are the workflows that apply to the entire site.

This workflow updates the company column of the following list when it runs.

company column of the below list 

Use the following procedure to create a site workflow.

Step 1: Open Visual Studio.

Step 2: Select "SharePoint" -> "2010" -> "Sequential Workflow".
 
Sequential Workflow

Step 3: Add the name of the Workflow.
 
Add the name of Workflow

Step 4: Ensure that the Check box is checked and that history list and task list are selected.
 
history list and Task list

Step 5: In the next window check the check box for User Manually start.
 
window check box

Step 6: Click "Finish", the next screen will display as below.
 
next screen

Step 7: From Toolbox select code activity.
 
Toolbox

Step 8: Inside code activity write the following lines of code:
 

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

{

    using (SPWeb web = SPContext.Current.Web)

    {

        SPList list = web.Lists["Manager"];

        foreach (SPListItem item in list.Items)

        {

            if (item["Company"] == null)

            {

                item["Company"] = "Please add company name.";

                item.Update();

            }

        }

    }

}

Step 9: Open All Site Content and click "Site Workflows".

Site Workflows

Step 10: The Added site work flow will be shown. Click it.
Added site work flow

Step 11: The Workflow will update the item company when it runs.
 
update  

Up Next
    Ebook Download
    View all
    Learn
    View all