Module #17: Custom Activities Lab #3
Course: Advanced SharePoint Development Estimated Time to Complete: 60 minutes Objectives: · Create a custom workflow activity for SharePoint Designer Operating Notes: · None Deliverables: · None
|
Overview: Let’s create our own custom workflow using SharePoint Designer
Exercise 1 – Create a Custom Activity
Purpose: Create a custom activity to be used by SharePoint Designer
Result: Custom Activity
Task 1 – Create a Project
- Open Visual Studio
- Select the File->New->Project
- Select Visual C#
- For template, select Workflow project type.
- Select the Workflow Activity Library template.
- For Location, type C:asp
- For Name, type CustomActivities
- Click OK
- Rename Activity1.cs to EncryptDocument.cs
- Right click the project, select Add Reference
- Add the following references:
- C:program filescommon filesmicrosoft sharedweb server extenstionsisapiMicrosoft.SharePoint.dll
- C:program filescommon filesmicrosoft sharedweb server extenstionsisapiMicrosoft.SharePoint.WorkflowActions.dll
- C:Program FilesMicrosoft Enterprise Library 3.1 – May 2007BinMicrosoft.Practices.EnterpriseLibrary.Common.dll
- C:Program FilesMicrosoft Enterprise Library 3.1 – May 2007BinMicrosoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
- Right click the EncryptDocument shape, select View Code
- Add the following using statements for the Workflow code:
- using Microsoft.SharePoint;
- using Microsoft.SharePoint.Workflow;
- using Microsoft.SharePoint.WorkflowActions;
- Since we are going to use Enterprise library to do our encryption, add the following using statements:
- using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
- using Microsoft.Practices.EnterpriseLibrary.Security;
- using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;
- Add the following Execute method:
|
- Add the following property, this will provide access to the workflow context back to our code:
|
- Add the following ListId property:
|
- Add the following ListItem property:
|
- Add another Activity, name this one DecryptDocument
- Add the same using statements (steps 13,14) and the same properties (steps 16,17,18)
- Add the following Execute method:
|
Task 2 – Strong Name the assembly
- In the Solution Explorer, Right Click on Properties
- Click the Signing tab
- Check the checkbox, Sign the Assembly
- Select the New option from the Drop down below
- For Filename, type DocumentEncryption
- Uncheck the “Protect my key file with a password” option
- Compile the project
Task 3 – Copy to the GAC
- Copy the EncryptDocument.dll to the C:windowsassembly directory
- Copy the Enterprise Library dlls to the GAC as well
- C:Program FilesMicrosoft Enterprise Library 3.1 – May 2007BinMicrosoft.Practices.EnterpriseLibrary.Common.dll
- C:Program FilesMicrosoft Enterprise Library 3.1 – May 2007BinMicrosoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Task 4 – Modify the web.config file
- Open web.config file in the C:inetpubwwwrootwssvirtualdirectories100 directory
- Add the following element to the System.Workflow.ComponentModel.WorkflowCompiler element:
|
- Save and close the web.config file
- Open Enterprise Library Configuration tool (shortcut on the desktop)
- From EntLib, open the web.config file
- Right click the “C:inetpub…” node, select New->Cryptography Application Block
- Right Click the Symmetric Providers node, select New->Symmetric algorithm provider
- Select DESCryptoServiceProvider
- Click Ok
- In the Cryptographic Key Wizard dialog, Click Next
- Click Generate
- Click Next
- Save the key file to the c:inetpubwwwrootwssvirtualdirectories100 directory, call it EncryptIt
- Click Save
- Click Next
- Select Machine Mode
- Click Finish
- Click the Cryptography Application Block node
- For DefaultSymmetricCryptoProvider, select the DESCryptoServiceProvider
- Save the web.config file
Task 5 – Create an ACTIONS file
- Create a file in C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATE1033Workflow called ENCRYPT.ACTIONS
- Copy the following to the file:
|
Task 6 – Create a workflow to use the Encryption action
- Reset IIS
- Open SharePoint Designer 2007
- Open your site (http://loclhost:100)
- Select File->New->Workflow menu command.
- For Name, type “Encrypt It”, select Shared Documents from the dropdown
- Click Next
- Click Actions, select the More Actions
- Click the dropdown for the Select a Category and choose “Encryption”
- In the Choose an Action box, select the “Encrypt a document/item” activity
- Click Add.
- Click on “this” option in the Action
- From the Choose List Item dialog box, select the “Current Item” option
- Click OK
- Click Finish
Task 7 – Run the workflow
- Add an item to the document library
- Right click the JavaScript dropdown, select workflows
- Click Encrypt It
Task 8 – Try to open the document
- Click the document, Word should fail to open it…it is encrypted!!!
Task 9 – Create a workflow to use the Decryption action
- In SharePoint Designer 2007, select File->New->Workflow menu command.
- For Name, type “Decrypt It”, select Shared Documents from the dropdown
- Click Next
- Click Actions, select the More Actions
- Click the dropdown for the Select a Category and choose “Encryption”
- In the Choose an Action box, select the “Decrypt a document/item” activity
- Click Add.
- Click on “this” option in the Action
- From the Choose List Item dialog box, select the “Current Item” option
- Click OK
- Click Finish
Task 10 – Run the workflow
- Add an item to the document library
- Right click the JavaScript dropdown, select workflows
- Click Decrypt It
Task 11 – Try to open the document
- Click the document, Word will open…it is decrypted!!!