Tuesday, May 8, 2007

Adding Custom Build Steps to a Visual Studio Project

Developing a solution to deploy a timer job involves modifying the CSPROJ file (an MSbuild file) to call the MakeCab utility - this creates a WSP file.

I found that adding an Import statement referring to the custom Targets file (in this case named BuildSharePointPackage.targets) from within the CSPROJ file didn't always produce the right output.

The cause was that MSBuild executes the last build target in order of appearance of Import statements. The csproj file included:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<
Import Project="BuildSharePointPackage.targets" />

The BuildSharePointPackage.targets file did not call any of the standard compile statements in the Microsoft.CSharp.targets file used to build C# projects, so the dlls were not getting rebuilt, and old versions os the dlls were being placed in the WSP file.

The solution was as follows:
  1. Set the DefaultTargets attribute in the Project element of the csproj file to equal the Name attribute of the Target element in the custom targets file:
    <Project DefaultTargets="BuildMossPlus" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  2. Add a DependsOnTarget attribute to the Target element in "BuildSharePointPackage.targets":

    <?xml version="1.0" encoding="utf-8" ?>
    <Project DefaultTargets="BuildMossPlus" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      
    <PropertyGroup>
        
    <MakeCabPath>"C:\Program Files\Microsoft Cabinet SDK\BIN\MAKECAB.EXE"</MakeCabPath>
      </PropertyGroup>
      
    <Target Name="BuildMossPlus" DependsOnTargets="$(BuildDependsOn)">
        
    <Exec Command="(SOME COMMAND)"/>
      </
    Target>
    </Project>


(with help from the MSBuild Team Blog)

SPSchedule String Formats (the FromString method)

When establishing timer jobs by defining an SPSchedule in a feature receiver (as per Andrew Connell's excellent article), the schedule can be entered using the FromString method of the SPSchedule class - see this post by Mark Arend for the acceptable string formats.

Note that this is a static method!

There is a lot of choice and flexibility in the permitted formats - some examples are "every 15 minutes", "hourly between 10 and 12" and "monthly at 1 09:00:00"

Tuesday, May 1, 2007

Connecting to Two Web Parts with a Different Parameter for Each

Had a solution requiring a single drop-down list in a dataview web part to filter the contents of two other data view web parts, each of which required a different field as the input parameter - i.e. the Controls web part was to be filtered by Control Refs and the Gaps web parts was to be filtered by Gap Refs. The two fields (Control Refs and Gap Refs) are multi-select lookup columns in the Risks list.

After much experimentation (and a fair bit of cursing!), I found the answer.

The dropdown dataview uses the following code for each row. The important points to note are the concatenation of the two required field values in the fields variable, and the concatenation of the two consumer GUIDs in the GenFireCOnnection call.

<option>
    
<xsl:attribute name="value">
        
<xsl:variable name="cursel">dvt_curselkey={<xsl:call-template name="dvt.gencurselkey"><xsl:with-param name="RowPath" select="." /></xsl:call-template>}</xsl:variable>
        
<xsl:variable name="fields">@Control_x0020_Refs=<xsl:value-of select="ddwrt:ConnEncode(string(@Control_x0020_Refs))" />#@Gap_x0020_Refs0=<xsl:value-of select="ddwrt:ConnEncode(string(@Gap_x0020_Refs0))" /></xsl:variable>
        
<xsl:text>javascript:</xsl:text>
        
<xsl:value-of select="ddwrt:GenFireConnection( concat( 'g_1a7694bc_1a99_427e_aece_bcbfdf0ba2b9#g_c79865fa_2833_4543_aefe_0a8f466211aa*', $fields),string($cursel))"></xsl:value-of>
        
<xsl:text>;</xsl:text>
    
</xsl:attribute>
    
<xsl:if test="$dvt_curselkey=@ID">
        
<xsl:attribute name="selected">true</xsl:attribute>
    
</xsl:if>
    
<xsl:value-of select="@Risk_x0020_Ref" /> - <xsl:value-of select="@Title" />
</
option>

Data Source Details in SharePoint Designer Fails to Show List Data

I have a list with a calculated value which is based on two other text values. Having entered a few test items in the list, the Data Source Details pane in SharePoint Designer was reporting an error with retrieving data for that list.

Further investigation revealed that one of the paths through the formula for the calculated column was returning a number rather than a string. This incorrect data type was causing the failure in the Data Source Details

Friday, April 27, 2007

Why Use the Custom Zone for Administrators

The model logical architecture released a while ago by Microsoft for a corporate MOSS deployment includes a configuration that really had me wondering "Why?" - that is the use of the custom zone for administrative access to all the sites.

One answer I have come up with - by assigning a policy to the custom zone for the SharePoint administrator user group, and granting full control in this policy, then the administrators are guaranteed to have full control over all sites and content in the delpoyment. Note that this is assuming an AD group named "SharePoint Administrators" exists in the domain.

The permissions applied in a policy override all other permissions in sites, so even if a user with site admin rights had removed all explicit permissions for the SharePoint Administrators user group from their site, the policy enforces access.

Sunday, April 22, 2007

Usernames in Data View Web Parts

Data View web parts by default offer the "friendly" name in the UserID parameter - if the logon username is required, find the ParameterBinding element with the name of UserID in the Data view's XSL, and change the Location attribute value from CAMLVariable to ServerVariable(LOGON_USER)