VSTO, Sharepoint, Workflow
Recently I was working on a large enterprise DMS demonstration. It was a custom demonstration of the new DMS capabilities within MOSS but included a lot of interfacing with Outlook. I was really excited to work on the project because I love VSTO and it's been awhile since I had the opportunity to really focus on a solution using it. I've been a VSTO supporter since the day I found out we could finally create .NET assemblies for automating Office applications. Yes, I hemmed and hawed and whined. My original blog had a list of things I hated and things I loved but VSTO has always been the shimmering star in the sky that would eventually do away with VBA and all the headaches that went along with it. It was like opening up a new book when I got to download VSTO SE and attempt to create an application level custom task pane for Outlook 2007 and, you know what, it was easy.
Where things got a bit confusing was the interaction between VSTO, Outlook and Sharepoint. I still haven't quite figured this out and I'd love to get some time to really test it. The basic background: A new email comes in, user, via a custom attachment context menu addition, selects to "profile it to Sharepoint." The Sharepoint document library which would receive the new item has a workflow associated to it to begin when a new item is added. The workflow does a bunch of things not important to this discussion.
Things were well until I needed to debug the workflow. I kept attaching to the WP process but the workflow never engaged... finally, after some searching I discovered that the workflow was actually running under the Outlook process. I pinged a VSTO PM, a MOSS workflow team PM... sent some code... changed some code but, to this moment, the workflow always engages under the Outlook process. My theory is that the behaviour is due to running in a single machine under Virtual Server. Surely when the Outlook client is actually on a workstation and the server is processing the workflow, this behaviour wouldn't happen. I haven't had time to test it yet but it was an interesting loophole to get through while doing development.
Another interesting aspect of this particular was demo was the need to convert an Infopath form to a static image, preferrably a TIF image. I was all excited originally because I knew from early documentation that this was a built-in feature of MOSS 2007 and, of course, I love playing with new features. It was only after struggling with some code (and a quick google search) that I discovered this feature was removed. In order to make a work-around, I decided I could convert the Infopath form to a webpage, then in the background print the webpage using a TIF printer driver. This would have worked, I think, however, after spending time waiting for the conversion to actually happen (the code ran fine, the conversion just never actually happened), some googling, I discovered that conversions do not work on images running a domain. I never did get to test it but will be interested to see how it might work. For my demo, I simply loaded up the Infopath form in the Infopath client, printed it using a TIF printer driver and hoped the client wouldn't notice the thing loading in the background!
It wouldn't be a blog post without some code though, right. Afterall, you likely aren't here to hear about my own personal development battles (well, maybe it will help you at some point). In the course of this demo I needed to add a couple of custom actions including a custom item action associated only to a particular content type. It is easy enough to add an item a menu as you can see from the xml snippet below. Notice the Registration Type and Registration ID settings on the first one. This associates this item dropdown menu item with a particular content type. Simply add the ID of the content type and you are good to go! The other cool thing about these custom actions is the ability to send over information to the custom page handling the action. As you can see, I am sending over the ItemID for the item context menu and the SiteURL for the custom actions menu. I still need to associate the second item, the actions menu item, with a particular list type as well. I believe I can do this but for the demo it didn't matter so I didn't bother to spend time figuring that out.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Per Item Dropdown (ECB)-->
<CustomAction
Id="MyID"
RegistrationType="ContentType"
RegistrationId="0x01010100B349F23D04F14f74BE298C74DEE2D231"
Location="EditControlBlock"
Sequence="106"
ImageUrl="/_layouts/images/perssite.gif"
Title="My Title Here">
<UrlAction Url="/_layouts/AMNCustomLayouts/MyCustomPageHere.aspx?Item={ItemId}"/>
</CustomAction>
<!-- Document Library Toolbar Actions Menu Dropdown -->
<CustomAction Id="MyProject.DocLibActionsToolbar"
RegistrationType="List"
RegistrationId="101"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
ImageUrl="/_layouts/images/crtpage.gif"
Description="My Description Here"
Title="My Create Title Here">
<UrlAction Url="/_layouts/MyCustomFolder/MyCustomPage.aspx?List={SiteUrl}"/>
</CustomAction>
</Elements>