How to start the default approval workflow programmatically

Today I was trying to find a way to programmatically create a publishing page and start the default approval workflow attached to the pages library. The reason that I had to programmatically start the workflow (instead of relying on SharePoint to automatically start it for me) was because my code was running under the system account (in this case under a WCF web service IIS process) and, since SP1, SharePoint will not automatically start a workflow if the list item is being changed by the system account (see this blog post for more information).

The main requirements I needed to solve were:

1) Determine what is the default content approval workflow associated with the Pages library.

2) Start the approval workflow when a Page is programmatically added to the Publishing Pages list but only if approval is enabled on the list.

3) Pass the default association data to the workflow (without asking the user for more information).

Here is the code for the solution I found:

I hope you find this code sample useful.