Simple Document Workflow
August 3, 2008Using
MOSS 2007
Windows Server 2003
Visual Studio 2008
SharePoint Extension for Visual Studio 2008
Setup
- In SharePoint, Set up two Document Libraries
- Source Document Library
- Destination Document Library
Instructions
- VS 2008/File/New/Project/Visual C#/Office/2007/SharePoint 2007 Sequential Workflow
- Name the Project
- OK
1st New Office SharePoint Workflow Dialog
- Keep name of Workflow
- Enter URL of the site contianing the Document Libraries ( ie, if the URL is http://localhost/Source Document Library, use http://localhost/ )
- Next
2nd New Office SharePoint Workflow Dialog
- [checked]Keep Automatically associate workflow (default)
- Library or List: Source Document Library
- History list: Workflow History (default)
- Taks list: Tasks (default)
- Next
3rd New Office SharePoint Workflow Dialog - Depends on what you are trying to accomplish
- [checked] Manually by others
- [checked] When an item is created
- [checked] When an item is changed
- Finish
- Double-click Workflow1.cs in Solution Explorer (if not already open)
- Click on onWorkflowActivated1
- In Properties, give the correlation token a name (something descriptive to the workflow)
- Expand CorrelationToken property. In the OwnerActivityName field, select Workflow1 from drop down. It’s Workflow1, which is the default name of the Workflow. If you change the name of your Workflow, you have to change this as well.
- From Toolbox, expand Windows Workflow v3.0
- Drag and drop the Code element under onWorkflowActivated1
- From Toolbox, expand SharePoint Workflow
- Drag and drop the LogToHistoryListActivity element under codeActivity1
- Double-click on onWorkflowActivated1 to open up the code window
- Add ‘public string logHistoryDescriptions;’ and ‘public string logHistoryOutcome;’ above the Workflow1 function
- Add ‘this.workflowId = workflowProperties.WorkflowId;’ in the onWorkflowActivated1_Invoked function
- On Workflow1.cs(Design), Double click the codeActivity1 to access the codeActivity1_ExecuteCode function
- Use the following code:
//Copy the document, using the same file name in the destination libarary
workflowProperties.Item.CopyTo(workflowProperties.Web.Url + “/” + “Destination Document Library/” + workflowProperties.Item.File.Name);
//log the activity
this.logHistoryDescriptions = “Attempted file copy of ” + workflowProperties.Item.File.Name +
” ” + “From: ” + workflowProperties.List.Title +
” ” + “To Destination Document Library”;
this.logHistoryOutcome = “Successful”;
- Click logToHistoryListActivity1 from the Workflow Design view
- On the properties screen, change the HistoryDescription property and the HistoryOutcome property.
- Select the HistoryDescription property (put your mouse in the empty text box beside it)
- Hit the ellipses control (will show up at the end of the empty text box. In the “Bind …. To an activity’s property” menu, choose logHistoryDescription which represents our internal variable (the one that we set in code).
- Do the same thing for the HistoryOutcome Property, choosing the logHistoryOutcome variable
- Build the project
- May possibly get Attach Security Warning dialog, Click Attach
- May get a Script Debugging Disabled dialog, Click Yes
- Project will open up the SharePoint site to the Source Document Library. The workflow should be automatically attached to the Source Document Library. If not, select Settings/Document Library Settings/Workflow Settings and attach the workflow.
∞