Archive for July, 2009


I’ve been working over the past few days with a custom workflow I’m building in Visual Studio 2005 that’s responsible for notifying users when specific criteria was met. Inside the workflow, I have a few sendEmail functions responsible for building the content within the email message:

1
2
sendEmail1.Body += "<font face=\"Arial\">This is the body of my email.<br/><br/>";
sendEmail1.Body += "Adding some information for users that will describe some detail about this item.</font>";

The above worked well until I started to see some truncating in my emails. I did some comparisons and found that the truncating would occur when the character count exceeded 2048 characters. I figured this couldn’t be the limit for a string in .NET so I did a bit of digging around and finally discovered that the root of the issue was because I didn’t have any line breaks in my string: “\r\n”. Once I inserted those at specific intervals, the truncating disappeared.

Awesome! Hope this helps someone else out there.

Triggering SharePoint workflows programmatically from within a custom built Visual Studio workflow is not difficult once you know where to look. Tony Testa wrote a great post on this very same thing that describes these concepts in more detail than I will — so go check that out if you haven’t already. I had to tweak his concept a little bit because I was doing this within an already running workflow that belonged to a content type not a list.

So in my scenario, I had a single workflow tied to a Content Type, and because I knew there was only one workflow, I used index at 0 to get the current workflow association. If your workflow is tied to a list, then you may not need to call ContentType, you might be able to use:

1
SPWorkflowAssociation workflowAssociation = workflowProperties.List.WorkflowAssocations[0];

If you have multiple workflows tied to a Content Type or a List, you will need to grab the Guid associationId for that workflow instead of using the index.

Finally, once I have my workflow association configured, I can start my workflow by passing it the parameters it needs:

1
2
3
4
5
if (workflowProperties.Site.WorkflowManager.GetItemActiveWorkflows(setLeaderItem).Count == 0)
{
    SPWorkflowAssociation workflowAssociation = workflowProperties.Item.ContentType.WorkflowAssociations[0];
    workflowProperties.Site.WorkflowManager.StartWorkflow(setLeaderItem, workflowAssociation, workflowAssociation.AssociationData, true);
}

The IF block is there to check if any active workflow are running on that list item. If there aren’t, it attempts to start the workflow. There you have it! That should trigger the workflow on the list item you specified.

Powered by WordPress | Theme: Motion by 85ideas.