devtrends.com
 

Custom Workflow Actions (Part 2 of 3)

Filed under: SharePoint, Visual Studio — Tags: , — admin @ August 24, 2008 8:22 pm

…this is a continuation of Custom Workflow Actions (Part 1 of 3)

As a recap, we are creating a custom workflow action that allows you to send an email with the attachments from a specified list in your site. The custom workflow action will allow you to configure four user input fields: (a) the Email Content; (b) the Send From Email; (c) the SMTP Host; and (d) the Associated List.

Although this project can be broken down into three sequential steps, these three steps are so closely intertwined that content from all three are required by the other three. With that stated, read all three sections, play around, then begin your actual development. The three steps are:

Step One: Create and Compile your .NET Workflow Activity
Step Two: Modify or Create .ACTIONS file and Add to Authorized Assemblies
Step Three: Deploy to WSS server and GAC

Step Two: Modify or Create .ACTIONS file and Add to Authorized Assemblies

First we will sign our new assembly as was created in Part 1 of 3 of this article. The signing process is required as we will extract the public key token from the assembly to use in the .ACTIONS file and the authorized assemblies list.

Let’s begin by opening up the Visual Studio project we created in Part 1 of 3, so open Visual Studio 2008.

Signing Assembly

Once the project is open, click on Project and then the project Properties menu option.

First, in the project properties tab for informational purposes, look at the Assembly name and the Default namespace; these should be the same as your class and the name of your project when you created the project.

Click on the Signing side-tab, check the box to Sign the assembly and then select the dropdown list and choose <New…>.

In the Create Strong Name Key window, type in the Key file name, using the same name as your project and class, uncheck Protect my key file with a password, and then click OK.

Your project should now be signed, as shown below:

Acquiring the Public Key Token

Hopefully by now your code from Part 1 of 3 compiles successfully. If not, you must first fix and successfully compile your code. After your code is compiled, you will need to acquire the public key token from the compiled code. This process is done through using the Strong Name Tool (sn.exe) application that comes with the Visual Studio environment.

http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.80).aspx

To simplify acquiring the public key token, we can add this application as an external tool in the Visual Studio environment. Click on Tools and then External Tools…

Add a new External tool, name the title Display Public Key Token, with command: C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sn.exe, and arguments: -Tp “$(TargetPath)”. Click OK.

Note: For those with Visual Studio 2005, the sn.exe tool is not located in the location as specified in this article. Search for sn.exe on your computer to determine the location.

Click on Tools again, and this time choose Display Public Key Token from the menu. The Output window should display and the token will be listed in the contents of that window:

Remember the public key token as you will use it twice during the rest of this Part 2 of 3.

Modify or Create .ACTIONS file

The .ACTIONS file defines how the Workflow action will be displayed SharePoint Designer 2007. The .ACTIONS file also defines how data is transformed to the Workflow code as created in Part 1 of 3.

Although this goes against standard procedure, we are going to add the actions configuration to the existing WSS.ACTIONS file. Be sure to back up the current WSS.ACTIONS file prior to editing.

Open WSS.ACTIONS in your favorite text editor and scroll to the bottom of the text document. Find the last </Action> closing tag (“Action”, singular not plural) and paste the follow code immediately following the closing action tag:

<Action Name=”Email List Attachments”

ClassName=”devtrends.EmailAttachments.SendEmailwithListAttachments”

Assembly=” devtrends.EmailAttachments, Version=1.0.0.0, Culture=neutral, PublicKeyToken=977438f55cbfd7aa”

AppliesTo=”all”

Category=”devtrends”>

<RuleDesigner Sentence=”Send %1 from %2 via SMTP host %3. Send attachments from list %4.”>

<FieldBind Field=”To,CC,Subject,Body” Text=”this message” DesignerType=”Email” Id=”1″/>

<FieldBind Field=”FromUser” Text=”this user” Id=”2″ DesignerType=”TextArea”/>

<FieldBind Field=”SMTPServerName” Text=”SMTP Server” Id=”3″ DesignerType=”TextArea”/>

<FieldBind Field=”ListId,ListItem” Text=”this list” Id=”4″ DesignerType=”ChooseListItem”/>

</RuleDesigner>

<Parameters>

<Parameter Name=”To” Type=”System.Collections.ArrayList, mscorlib” Direction=”In” />

<Parameter Name=”CC” Type=”System.Collections.ArrayList, mscorlib” Direction=”Optional” />

<Parameter Name=”Subject” Type=”System.String, mscorlib” Direction=”In” />

<Parameter Name=”Body” Type=”System.String, mscorlib” Direction=”Optional” />

<Parameter Name=”FromUser” Type=”System.String, mscorlib” Direction=”In” />

<Parameter Name=”SMTPServerName” Type=”System.String, mscorlib” Direction=”In” InitialValue=”127.0.0.1″ />

<Parameter Name=”__Context” Type=”Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions” Direction=”In”/>

<Parameter Name=”ListId” Type=”System.String, mscorlib” Direction=”In” />

<Parameter Name=”ListItem” Type=”System.Int32, mscorlib” Direction=”In” />

</Parameters>

</Action>

Replace the public key token value in the first line with the public key token you acquired from earlier in this Part 2 of 3. Save the WSS.ACTIONS file.

Authorize the Assembly

In this step we will add our new assembly to the authorized assembly list. This list is stored in the web.config file for your SharePoint Services installation. The standard location for this file will be: C:\Inetpub\wwwroot\wss\VirtualDirectories\80\

Open the web.config file using your favorite text editor and scroll to the bottom of the web.config file. In the System.Workflow.ComponentModel.WorkflowCompiler, authorizedTypes section add the follow line:

<authorizedType Assembly=”devtrends.EmailAttachments, Version=1.0.0.0, Culture=neutral, PublicKeyToken=977438f55cbfd7aa” Namespace=”devtrends.EmailAttachments” TypeName=”*” Authorized=”True” />

Be sure to change the PublicKeyToken field to match the public key token as was acquired earlier in this Part 2 of 3.

Save the web.config file.

Please continue to Custom Workflow Actions (Part 3 of 3)

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Blog Categories
  • BlackBerry (1)
  • Group Policy (1)
  • Linux (1)
  • Microsoft Office (1)
  • Networking (1)
  • Printing (3)
  • SharePoint (6)
  • SQL (1)
  • Visual Studio (3)
  • Windows XP (1)

  •