Tuesday, April 29, 2008

Day of Dot Net - West Michigan

Woo hoo, accepted as a speaker at the 2008 Day of Dot Net - West Michigan! Good sessions...I want to see the one about using the Wii remote, that'll be very cool. I'll be talking about the fun I've been having with SharePoint, VS 2008, and Workflows. Good stuff!

WM Day of .Net May 10, 2008 - I'll be there!

Showing icons in a list view

My customer threw me a challenge: instead of your typical Red/Amber/Green SLA indicator, they also want to show Blue if they've exceeded the SLA target. And no yellow - either you're red, missed; green, on; or blue, exceeded. So much for using the KPI interface!

I started looking in to the KPI Dashboard sample to see if I could somehow customize this, but after an hour and a cup of Starbuck's it was still none too clear. Then the coffee cleared away the neurons & I recalled seeing discussion on using the spankin' new XSLT Data Viewer. I had done used this with SPS 2003 and it was pretty good then...and it's better now with MOSS.

The XSLT Data Viewer is a MOSS goodie, sorry WSS'ers. To use it, I fired up SharePoint Designer, opened up my list, changed to the 'Split' view, then with a right click I chose the Convert to XSLT Data View option.

In my list I have a SLA column, a Target column, and a Status column. I wanted the indicator in the Status column.

After a few seconds (slow on the VPC for some reason) I was able to view the list. Looking at the XSLT, for the Status column, I changed what was there to:

<!--Status-->
<TD Class="{$IDAVVHVE}"><xsl:choose>
<xsl:when test="@SLA amp-gt; @Target">
<img src="/_layouts/images/KPIDefault-Blue.gif" alt="Exceeded SLA Target"/>
</xsl:when>
<xsl:when test="@SLA= @Target">
<img src="/_layouts/images/KPIDefault-2.gif" alt="Met SLA"/>
</xsl:when>
<xsl:when test="@SLA amp-lt; @Target">
<img src="/_layouts/images/KPIDefault-0.gif" alt="Missed SLA"/>
</xsl:when>
</xsl:choose>
</TD>

Change the 'amp-gt;' to an ampersandgt; (I should find a better blog page) and 'amp-lt;' to the ampersandlt; and you're good to go!

Now I need to come up with a nice shape for the Blue icon. Blue Moon? mmmm, tasty, good idea!

Tuesday, April 08, 2008

EditControlBlock registrationtypes

Been working on adding a new item to the SharePoint drop down menus...easy to do by creating a feature, then defining the custom action one wants to add in. But...I only want my new menu item available for documents. One of my testers saw that the new menu item was on the folder drop down list also, and what do you know, test case failed!

So...I could either add code that points out to the dear user that one ought not use this with folders, or see if there was a way to hide the new menu item from folders - that is, the new menu item appears only for documents.

RegistrationType and RegistrationID to the rescue. These items are part of the custom action XML defined by the Feature.XML. Here's what I've been able to determine. RegistrationType allows for "ContentType" and "FileType" values, as well as List and ProgID.

Specifying "ContentType" is what I'm after. This will allow me to associate the new action with a specific content type. The RegistrationID element is used to specify the ID of the content type. To get this ID, open your document library settings, in the ContentType section click on the content type of interest, then grab the hex string in the URL after the "ctype=" parameter. Paste this value in to the RegistrationID value.

Alternatively, if I only want this feature to appear for ".xls" files, then I'd use the FileType RegistationType, and the value "xls" for the registationID. Repeat the CustomAction block for other file types.

The completed Feature.XML looks like:

Feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="1a8e5fae-577f-4cbd-addb-a31d875300a6"
Title="Copy Document"
Description="My custom document copy feature"
Version="1.0.0.0"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="CopyDocument.xml" />
</ElementManifests>
</Feature>


CopyDocument.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Per Item Dropdown (ECB)-->
<CustomAction
Id="Custom.PromoteDocument"
RegistrationType="ContentType"
RegistrationId="ctype=0x01010038C4691B76BEB34CB53E65CADDF82AD3"
Location="EditControlBlock"
Rights="EditListItems"
Title="Promote Document">
<UrlAction Url="~site/_layouts/MyCustomCopyDocument.aspx?List={ListId}&ID={ItemId}"/>
</CustomAction>
</Elements>

Note also the use of {ListId} and {ItemID} - I use this with my code behind file to get the SPList and SPListItem from the content SPWeb. With these I can then get to the attachment object of the SPListItem, so I can copy that document around.