How SharePoint Wikis Work

Posted by Dave on Aug 1st, 2008
2008
Aug 1

This is going to be a work in progress for a little bit because I’m still figuring out bits and pieces of this, and likely will be for a little while yet. I’ll come back and edit this post as necessary.

This is a result of some more work I’m doing on the Community Kit for SharePoint. I’m revisiting our basic design for rendering wiki pages to see if it can be streamlined a bit, or made more versatile. At this point, I’m afraid the answer is “No” on both counts. With that said, I’ll attempt to save you some time - if you want to understand how SharePoint wikis work in order to extend their base processing you can stop here. This whole article will turn out to be nothing more than an intellectual exercise. To the best of my knowledge right now, Microsoft kind of closed the door on us. We are extremely limited in the options we have for extending the default wiki functionality. Instead, we have to rip and replace to get the additional functionality we need. I’ll cover that in a later blog post.

Nonetheless, it will be a fairly short article, and contains some interesting tidbits, so feel free to stick around. I’ll have another post in a week or two that walks through the CKS Wiki and explains how we overcame some of the limitations in the default wiki.

Let’s get started…

First, a few interesting tidbits:

  1. When you navigate to a wiki site in WSS, you are shown the “Home” page of the wiki instead of a regular default.aspx. This little bit of wizardry is accomplished by setting the (SPWeb).RootFolder.WelcomePage property for your site to a different URL, in this case the home wiki page. You can use this for any type of site. So, for example, if you wanted people to be taken to the AllItems view of a site’s document library any time they visited http://site_name, you could use code similar to this:

    SPSite sitecoll = new SPSite(”http://site_name”);

    SPWeb site = sitecoll.OpenWeb();

    SPFolder fldr = site.RootFolder;

    fldr.WelcomePage = “Shared%20Documents/Forms/AllItems.aspx”;

    fldr.Update();

    site.Update();

    site.Dispose();

    sitecoll.Dispose();

    This works for any page in the site. The default.aspx page is still available if they navigate directly to it, but it is no longer the “homepage” for the site.

  1. All wiki pages are based off of the wkpstd.aspx page in the 12\DOCUMENTEMPLATES folder. We’ll cover this more later, but if you simply want to make minor changes to the wiki pages, you can edit that page. All of the usual warnings apply about editing the out of the box SharePoint files, but unfortunately, there is no way to tell the default wiki to use a different page as its template. As you’ll see, we do use a different template in the enhanced wiki, but that’s because we largely rip out whole portions of this process and replace them with our own.

Now let’s get down to business. The process of handling wiki pages and wiki editing is remarkably simple, once you wade through it all and look at all of the moving parts. As I said, though, you have to look at this as a nice intellectual exercise because we cannot make use of much of it when we look to extend the wiki.

It all starts when we want to create a new wiki page. We can do this by either clicking the “New” button in the list or by clicking on a [[wiki link]] in an existing page, shown below:

Either way, SharePoint loads the CreateWebPage.aspx page from the Layouts directory.

CreateWebPage.aspx

The CreateWebPage page is nothing special technically, but it is part of the key to wiki functionality in SharePoint. If you’re not familiar, here’s what it looks like:

If you look at the code, you’ll see a pretty standard layouts page. The important parts of the page (the Name and Wiki Content fields) are displayed with a few lines of markup:

As I said before, it’s nothing to write home about, technically, at least not for the presentation so far. One interesting bit happens when you click the Create button. At that point, the click event handler comes into play. If you want to take a look at this, you need to open up the Microsoft.SharePoint.ApplicationPages from the app_bin folder of your web application (not the …12\ISAPI folder) in Reflector. Navigate through to Microsoft.SharePoint.ApplicationPages.dll\ Microsoft.SharePoint.ApplicationPages\CreateWebPage and then take a look at the SubmitBtn_Click method.

This method basically iterates through all of the fields submitted in the form and stores them in the corresponding field of a newly created SPListItem. Nothing really special, but it shows how the values get collected from the user and stored in the wiki item. One important part to note is the call to list.RootFolder.Files.Add. This creates a new file (and the associated SPListItem) in the list. The interesting bit is the second parameter: SPTemplateFileType.WikiPage. If you follow the Add method and look at what it does, you’ll see that the second parameter sets a path variable to “DocumentTemplates\wkpstd.aspx”. The Add method then creates and returns (as the new file in the wiki library) a ghosted instance of this page. In other words, every wiki page in every wiki on your site uses the file located at …12\TEMPLATE\DOCUMENTTEMPLATES\wkpstd.aspx as a template. With all of the standard caveats about editing the default SharePoint files, if you change that one file, it will reflect in every wiki page that has not been unghosted. Not too useful, perhaps, but interesting.

HEY! Did anyone catch the fact that the new wiki page is created programmatically as a ghosted page?! As far as I know, there is no other way to do that programmatically, but it sure would be a pretty slick piece of functionality to make use of sometimes. Unfortunately, the AddGhosted method is marked as internal and so we can’t make use of it. Bummer.

 

A few final things to note about CreateWebPage.aspx:

  1. It displays the fields from the current list via a ListFieldIterator. This means that if you add columns to your wiki list, they WILL show up on this page. Likely, that’s what you wanted, but perhaps not. Anyway, it’s what happens.
  2. It always creates the SPListItem in the root of the list. Folders are not supported.

At this point, we have a new file in the wiki library named with the Name supplied by the user, with basic contents drawn from wkpstd.aspx and specific contents from whatever was entered by the user in the rich text control displayed for the Wiki Content field.

Converting Wiki Markup

So far, so good, except that the text has not been converted from wiki markup to HTML. It still contains a bunch of [[page]] entries. When do they get converted to links: or ?

This is the point where wikis start to take on a little bit of a split personality. There are two conditions in which wikis can be displayed:

  1. Normal Display - all wiki markup/links are converted to properly styled HTML and displayed to an enduser: or
  2. Editing Display - all wiki markup/links is shown unconverted as regular textual markup: [[my page]] or [[a new page]].

Looking at these one at a time…

Normal Display

When the wiki page is displayed for end users, the value of the WikiContent field (the name of the field in the wiki List) is displayed via: . Inside the wiki List, the field is a simple Multiline Text field with RichText = true

Note that the FieldName attribute references “WikiField”. In the UI, the field displays the name “Wiki Content” but the internal name is “WikiField” and that’s what we need to reference it by. You can see this if you mouse-over the field in the List Settings page and take a look at the status bar:

Because the field in the List is simply a MultiLine Text field, the FormField tag above causes it to display as a Rich Text field in the UI.

We’re now finally at the point where the wiki markup gets translated to HTML. It happens in the RenderFieldForDisplay method of the Microsoft.SharePoint.WebControls.RichTextField class. The method itself is pretty short, the meat of it for wikis being the following three lines:

    output.Write(”<div class=\”ms-wikicontent\”>”);

output.Write(field.GetFieldValueAsHtml(this.ItemFieldValue, base.ListItem));

output.Write(”<p></p></div>”);

The call to GetFieldValueAsHtml will eventually make a call to Microsoft.SharePoint.SPFieldMultiLineText.ProcessWikiLinks (assuming that WikiLinking is set to true for the RichTextField, which it is in our case). ProcessWikiLinks iterates through the ForwardLinks collection of the SPListItem that is our wiki page and converts the wiki links [[my page]] to this HTML if the target page already exists:

<a id=”ctl00_PlaceHolderLeftActions_RecentChanges_ctl00_RecentChangesIterator_ctl01_RecentChange” class=”ms-navitem” href=”/wsswiki/Wiki%20Pages/my%20page.aspx”>my page</a>

And this HTML if it does not:

<div><a class=ms-missinglink href=”http://moss1/wsswiki/_layouts/CreateWebPage.aspx?List={0971da62%2Da81d%2D4879%2Da11b%2D17bb362f76bb}&RootFolderUrl=%2Fwsswiki%2FWiki%20Pages&Name=a%20new%20page” title=”a new page - click to define topic”>a new page</a></div></div><p></p></div>

The latter snippet, as you can see, decorates the anchor tag with a class attribute that is responsible for the on-screen display that indicates the wiki page does not yet exist. Notice also the href attribute is a call to CreateWebPage.aspx. This starts the process for a new page, which we covered at the top of this article.

Notice that the text is converted for every page load. It is not converted and stored. For wiki links, this is preferred as pages can be added or deleted at any time, so we need to process the links based upon the current status of the pages. In the CKS Enhanced Wiki, we add a lot more markup parsing which would be expensive to do for every page load, so we handle that slightly differently. We’ll cover that in another post.

Editing Display

After all of the above, the editing display is easy. As we now know, our Wiki Content (WikiField) is just a multi-line text field in SharePoint. In the edit view, the standard EditForm.aspx page simply renders this as a regular RichTextField with the Rich Text Editor toolbar in place. Nothing happens to the text because it is stored in its raw form - i.e. with the wiki markup intact. We don’t need to convert the text, as mentioned above, because it is stored in the unconverted state. So, displaying the wiki field for editing is no different thatn showing any other SharePoint field for editing.

There is one minor element that does get added specifically for wiki fields: the little instructions blurb that shows up below the field:

This is handled in the Microsoft.SharePoint.WebControls.RichTextField.RenderFieldForInput method. After all of the other processing has happened, the following lines add this text:

if (field.WikiLinking)

{

output.Write(”<span class=ms-formdescription>”);

output.Write(SPResource.GetString(”WikiLinkInstructions”, new object[0]));

output.Write(”</span>”);

}

As you can see, the text itself is taken from a resource file. The RenderFieldForInput method also handles adding the proper JavaScript to the page to handle the RichText editor functionality by making a call to the SPUtility.TextAreaToRichTextClientScript method.

That’s it for editing.

One Other Point

One more thing that it is important to know is that the default wiki list limits the number of RichText fields it can contain to just one. This means that it is not possible to have >1 wiki field on an item.

Conclusion

So there you have it, a little waltz through the default SharePoint wiki to show how it handles converting wiki markup to HTML and the creation of pages. All in all, it’s pretty basic stuff. In a later post, I’ll cover how we change this process to overcome some internal designations and also add support for a lot more wiki markup and some other functionality.

Dave

 

International SharePoint Professionals Association

Posted by Dave on Jul 16th, 2008
2008
Jul 16

From Bob Fox:

The International SharePoint Professionals Association, also known as ‘ISPA’, is an independent, not-for-profit, community-driven organization dedicated to support SharePoint professionals and groups all around the world. The primary mission of ISPA is to promote the global adoption of SharePoint Technologies by providing support and guidance to the SharePoint community as a whole – by establishing connections between SharePoint professionals, groups, resources, education and information. ISPA is led and supported by volunteers across the world, and will focus on bringing the entire SharePoint community closer together.

ISPA’s first offering to the community is support to user groups around the world through free WSS v3 web sites for any group that becomes ISPA-affiliated. In addition, one of the goals of ISPA is to facilitate an exchange of ideas between user group leaders that helps increase the likelihood of their group’s success. Therefore, ISPA is providing leaders of user groups with access to collaborative spaces where they can interact with other user group leaders, sharing ideas, resources, best practices, guidance, and most importantly – support for one another.

ISPA has also established Regional Evangelists – existing community leaders who have previously exhibited a strong commitment to the promotion of the SharePoint community, and who have pledged to carry the ISPA message throughout their particular region. These evangelists are key local contacts who are available to work with local SharePoint professionals and user groups throughout their region to help promote the community and SharePoint. If you are interested in starting a user group, have an existing one, or need guidance – the ISPA Regional Evangelists are great resources who are available immediately to assist you.

Finally, as everyone knows, no community is complete without a web site, and ISPA is proud to announce the launch of its official site, http://www.sharepointpros.org. While the web site is still in the early stages of development, plans for multilingual support and exciting functionality that will assist anyone involved with SharePoint are on the horizon.

There’s more out on Bob’s blog, including a list of Regional Evangelists. I’m covering the Mid-Atlantic (PA, DE, MD, South Jersey).

There are a lot of things planned for the future of ISPA, so stay tuned. This is only just the beginning…

Any questions, feel free to ping me.

Dave

2008
Jul 10

This is the latest book from Andrew Connell. I have to admit, I got a review copy of this a few weeks back and skimmed through it pretty quickly. Since then, it sat on my desk under a pile of papers (literally, at one point I thought I had lost it…I really need to clean up my desk) waiting for me to get the chance to review it further.

My first impression upon skimming through it was that, as expected, it is pretty impressive. I do very little work with the publishing and WCM sides of MOSS but I couldn’t see anything that was missing from the book that you would need in order to complete a WCM project. Over the last few days, I’ve gone back in for a deeper read on some of the chapters. My opinion hasn’t changed, still impressive. So much so that I think even a dolt like me could do some of this stuff - I’m thinking of even taking a stab at building up a publishing site using the material from the book to help just so I can get some hands-on time with that side of the product.

If you’re wondering, here is the TOC: http://www.amazon.com/gp/reader/0470224754/ref=sib_dp_pop_toc?ie=UTF8&p=S00E#reader-link

If you are experienced with SharePoint, but just not the WCM/Publishing side, you’ll likely only skim the first four chapters. I have some background in WCM in general (Vignette, MCMS, a few now-defunct implementations, etc) so I might have skimmed it more than most. The nice thing about this book is that if you do have a background in SharePoint, you can easily skim through the pieces that you know already. I would advise you to not skip them entirely, though, as there are a few pieces that are unique to WCM buried in the rest of the “SharePoint 101″ content.

What I was really looking for was the hands-on pieces which begin in chapter 5. Here is where the fun begins. Moving quickly from base topics such as Site Definitions, Content Types, Lists and Master Pages, we move onto some more WCM-focused topics:

Customizing Navigation - comes into play sometimes in non-WCM implementations, but almost ALWAYS in WCM projects

Accessibility - Another big piece of any public facing WCM site. The chapter is short, largely, I think because there isn’t much of a story here for SharePoint, unfortunately. It covers the Accessibility Kit for SharePoint, but only through installation and implementation. I wish it went a little further, but perhaps that is something I need to discover for myself…

Field Types and Field Controls - Probably my favorite chapter. This is one of the best extensibility points for SharePoint.

Web Parts - Interesting, I don’t typically think of web parts in a WCM site, but I can see that I was wrong. Great coverage of the Content Query Web Part.

Workflow - My favorite topic…a good overview and provides the basics, thanks for the plug for my book, AC.

Search - I need to re-read this chapter and commit to memory. For some reason, I can’t get my hands around SharePoint Search. It just doesn’t stay in my brain. This is the first time I’ve seen a concise coverage of search that still seems to cover everything you need. For me, this will likely be the most useful chapter, if I can manage to remember it all

Authoring Experience - Love the coverage of customizing the Page Editing Toolbar.

Authentication and Authorization - Not specific to WCM sites. A must-read for anyone doing SharePoint.

Multiple-Languages and Devices - Variations, likely the hardest part of getting WCM right. Another must-read.

Content Deployment - critical to doing WCM right. Currently, Content Deployment in MOSS is a bit fragile - this chapter provides great coverage of how to get it working.

Offline Authoring - I have one client who massively overused this feature (implemented before I started there) and is having all kinds of problems. This chapter could have saved them a lot of hassle.

Tips, Tricks & Traps - This chapter alone is worth the cost of the book. Caching, page payloads, performance management, proper disposing, etc. All great stuff.

ASP.Net 2.0 Applications - At first glance, I thought this chapter was an afterthought, an add-on. It didn’t really seem to fit. However, when I looked at it more closely, it definitely fits. These days it is rare to find a company that doesn’t already have a significant investment in their website. If they are now implementing MOSS, it is likely that you will need to have MOSS and an ASP.Net website/application coexist for some period of time - perhaps quite lengthy. In addition, your WCM site may require additional application-type functionality outside of what SharePoint offers. This chapter touches upon all of the things you will need to be concerned about. After reading it, I wish this chapter were longer. It is definitely not an “add-on”.

So, all-in-all, a worthy addition to your bookshelf for anyone who does SharePoint. If you deal specifically with WCM, what the hell are you waiting for? Go buy this book.

Dave

PS: In the interest of full disclosure, yes, I got a free copy, and yes, AC is a friend of mine. However, I would have paid for it if I didn’t get a copy for free, and the fact that it was written by a friend is irrelevant. If the book sucked eggs, I would say so. It doesn’t. J

Office Geeks

Posted by Dave on Jul 10th, 2008
2008
Jul 10

Well, another pretty good meeting the other night. We took a slightly different tack this time. Rather than presenting a typical keynote, we had an open panel discussion - four local SharePoint developers/architects sitting at the front of the room answering any questions fired at them from the audience. The best part was that everyone got involved in answering questions if they had something relevant to say. It made things more like a discussion rather than a Q&A session. I think it went pretty well. I’d like to thank the four guinea pigs experts who joined me at the front of the room:

  • Stacey Bailey
  • Afshin Zavareh
  • Tony Testa
  • Dani Diaz

Thanks, guys, for sharing your knowledge and being willing to be put on the spot a bit.

We’ll likely re-run this format once/quarter.

In other Office Geeks news, we’re approaching our one year anniversary (October)! We’re kicking around some ideas to celebrate, we’ll let details slip soon.

Upcoming meetings

August - Tony Testa will be presenting, topic is still TBD, but some ideas were: My Site customizations and something about configuring search.

September - Building Enterprise Workflows

October - 1 Year Anniversary…details TBD

 

Thanks again to everyone who attended and participated this month. I hope you all found the meeting valuable

-Dave

Second whitepaper

Posted by Dave on Jun 18th, 2008
2008
Jun 18

My second whitepaper was published to MSDN: Building and Distributing Workflows in SharePoint Products and Technologies for Use in Customer and Partner Environments.

Here is the Table of Contents:

Contents

  • Overview of Workflows in Customer and Partner Environments
  • Planning and Designing for Multi-Environment Deployment
  • Defensive Coding
  • Supporting Customizations
  • When Things Go Wrong
  • Logging
  • Deployment
  • Documenting Your Workflow
  • Summary
  • Additional Resources

Enjoy!

 

Dave

Workflow Whitepaper on MSDN

Posted by Dave on Jun 11th, 2008
2008
Jun 11

I just received notice that the first of my whitepapers has been published on MSDN: Delivering Modular SharePoint Workflow Functionality. It covers the reasons and process for creating custom Activities, Actions and Conditions for SharePoint workflows. While it is ostensibly written for ISVs considering adding support for SharePoint workflows to their applications, the process and code is applicable to anyone adding custom Activities.

There is another one coming soon on how to build bullet-proof workflows that run in environments over which you do not have direct control. I’ll post when that one hits MSDN as well.

 

Questions, comments, complaints welcome…

 

Dave

SPWebConfigModification

Posted by Dave on Jun 5th, 2008
2008
Jun 5

Just a quick note here.

When you are adding a web.config entry via the SPWebConfigModification class, you need to specify a Name for the modification. Typically, it will look something like this: add[@name=\”CustomSiteMapProvider\”] . It is an XPath expression to uniquely identify the modification. The tricky part is that this name must match the name= parameter in the string added to the web.config (assuming you have one).

In other words, this is OK:

Name= add[@name=\”CustomSiteMapProvider\”]

Value= <add name=’CustomSiteMapProvider’ type=’MyNS.MyClass, MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx’ description=’Custom site map provider’ NavigationType=’Global’ />

 

 

Whereas this is NOT OK:

Name= add[@name=\”CustomSiteMapProvider\”]

Value= <add name=’MyNewSiteMapProvider’ type=’MyNS.MyClass, MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx’ description=’Custom site map provider’ NavigationType=’Global’ />

Note the difference in the name attribute in the Value and the Name of the modification.

This will become a problem when you attempt to REMOVE the entry. You will not be able to.

 

-Dave

2008
May 17

Thanks to everyone who attended my Code Camp session this morning, and for putting up with my “machine issues”.

As promised, here are the tools that I demonstrated:

STSDev - www.codeplex.com/stsdev

SharePoint Inspector: http://www.codeplex.com/spi

U2U CAML Builder: http://www.u2u.info/SharePoint/U2U%20Community%20Tools/U2U%20Caml%20Query%20Builder%202007%20v3.0.2.0.zip

 

SharePoint Tips Utility Pack: http://www.codeplex.com/spstipsUtilityPack

App Pool Manager: http://www.harbar.net/articles/APM.aspx

 

Reflector: http://www.aisto.com/roeder/dotnet/

“Attach to Process” script: http://www.andrewconnell.com/blog/archive/2006/05/10/3110.aspx [Note: You’ll need to change the process name in the script from “aspnet_wp.exe” to “w3wp.exe”]

 

One other thing I forgot to mention in all of the projector-problem mayhem: if you are interested in learning more about SharePoint and Office development, including FREE SharePoint developer training, please consider joining the Office Geeks User Group. We meet monthly at the Microsoft Office in Malvern. More information is available here: http://www.officegeeks.org/philly or by email: geeks_at_kcdholdings-dot-com.

Thanks again for attending this morning,

Dave

Free SharePoint Developer Training

Posted by Dave on Apr 8th, 2008
2008
Apr 8

Now that I’ve got your attention…the bad news. You need to be in the Philly area and able to come to our Philly Office Geeks meetings. Also, this is really a self-teaching opportunity. We’re going to provide the direction, information, resources and some support, but this is an opportunity for you to learn at your own pace and take things as far as you want to take them. We only meet once/month so we won’t be winning any speed-training awards. If you are interested in professional SharePoint training that gets you from 0 to 100 in 4 action-packed days, I recommend the Ted Pattison Group, specifically, the course I’m teaching in Philly in May. You can read more about it here: http://www.mannsoftware.com/Blog/?p=118

We’re kicking off the sessions at our April meeting (tonight, sorry for the short notice) by providing information on pre-reqs and information to get people started. The first actual “training” will happen at our May meeting.

With that said, here’s what you need to get started:

  1. A machine (physical or virtual) running Windows Server 2003 or 2008, all patched and updated
  2. WSS or MOSS, SP1 – trial version acceptable
  3. Visual Studio 2008. You can get by with 2005, but I’ll be demoing with 2008
  4. Lutz Roeder’s Reflector (http://www.aisto.com/roeder/dotnet/)
  5. SharePoint Designer 2007
  6. MOSS SDK: http://www.microsoft.com/downloads/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en
  7. WSS 3 SDK: http://www.microsoft.com/downloads/details.aspx?familyid=05E0DD12-8394-402B-8936-A07FE8AFAFFD&displaylang=en
  8. SQL – you can use the Express version that SharePoint installs – don’t let the VS install overwrite it
  9.  

Here are a couple of articles on setting up an environment:

However you get there, the end result needs to be a standalone SharePoint virtual environment with either MOSS or WSS, VS 2008, SharePoint Designer and the couple of tools mentioned above. We’ll be adding more tools as we go along.

Trial versions of all software is acceptable.  Also, I believe the 2 write ups above each mention installing VSTO.  We won’t need that so you can skip it.

Questions and support are being provided via our Yahoo Group: http://tech.groups.yahoo.com/group/PhillyOfficeGeeks

 

Dave

Workflow Cancellation Handlers

Posted by Dave on Mar 30th, 2008
2008
Mar 30

Another excerpt from the book:

 

Cancelling Workflows is similar in many ways to Fault Handling in our Workflows. If Fault Handlers are the catch block, then cancellation Handlers are the finally block. Workflows can be cancelled in a few ways and for any number of reasons:

    *    By unhandled exceptions

    *    By an administrator in the UI

    *    Explicitly based on a condition within the Workflow through the use of a Terminate activity

The Cancellation Handler allows us to perform any processing that needs to occur before the Workflow actually shuts down. One thing that is important to note is that there is no way to stop the cancellation of a Workflow once it has been initiated by any means.

So, if we can’t stop the cancellation of a Workflow, what can we do? The answer is really just about anything else. Off the top of my head, the following comes to mind:

    *    Notify a document owner that the Workflow has been cancelled

    *    Notify participants that the Workflow has been cancelled

    *    Just like with Fault Handling, if Tasks were already assigned, you should go back and either delete them or flag them as inactive.

    *    Again just like Fault Handlers, log the cancellation

 

So, with all of that out of the way, how do we actually catch a Workflow Cancellation event and respond to it? As I said when I started out this section, it is similar to Fault Handling. To work with the Cancellation Handler for the whole Workflow, click on the middle tab at the bottom of the designer palette (and shown above in Figure 9-4). This will reveal another palette used specifically for handling Workflow cancellations.

 

Also, composite activities can also contain specific, local Cancellation Handlers. This local Cancellation handler will be called if one of their child activities is cancelled, or executing when the Workflow is cancelled. Access this via a similar mechanism to the Fault Handler – right click on the activity and select View Cancel Handler.

 

One thing to note about Cancellation Handlers is that they may not exactly execute as you would expect. If you place a Cancel Handler globally on the entire Workflow, it would be logical to assume that it would fire any time the Workflow is cancelled – for any reason. Unfortunately, this is not the case. Because Cancellation can be handled locally, only the composite activities that have children executing at the time the error is thrown or the Workflow otherwise cancelled will have their Cancellation Handlers triggered. So, in the case of the global Cancellation Handler, this will only be triggered if the whole Workflow is cancelled – typically by an Administrator via the user interface.

 

In other cases, in order to get multiple activities executing simultaneously, you really need to be using the Parallel activity. If one branch of the Parallel activity causes the Workflow to be cancelled – for example by throwing an unhandled error, the other branch(es) of the Parallel activity will be notified that the Workflow is being cancelled. Individual composite activities within those other branches will also have their Cancellation Handlers triggered. However, the Parallel activity itself and the Workflow as a whole will not have their Cancellation Handlers triggered.

 

It’s all a little bit happenstance and highly dependent upon execution order, timing and which activities are executing at the time the cancellation is triggered. While you can generally plan out your Cancellation Handlers pretty well, there will be an experimentation aspect to it to see how things execute in your environment.

NOTE    For an example of the variable nature of Cancellation Handlers, in a nod to Mr. Heisenberg, I could consistently produce different results just by alternating between running my test Workflow in the debugger or outside the debugger. As I said, this all highly dependent upon exactly what is happening at the moment the cancellation is triggered. Your mileage may vary.

 

Next »