Thursday, June 14, 2007

Building an Accessible Internet Site with WCM: Setting Up the Solution

Latest project is to create an Internet site using MOSS that complies with accessibility web standards.

First step was a LOT of research. I found plenty of useful articles by Heather Solomon, Zac Smith, Cameron Moll and others, plus dashings of negative comments about quite how non-standard is the HTML pumped out by SharePoint. Sounds like a fair bit of work ahead!

During my travels around the web, I came across a nice idea from Phil Wicklund on managing SharePoint development across a team. The great thing about starting a new project is that it gives the opportunity to apply best practices, so I am combining Phil's approach of reproducing the 12 hive folder structure, but will be deploying via a feature rather than via Xcopy. The downside of this is that deployment during development is slower, but I prefer to always build the WSP file as this sorts out any deployment issues very early in the development cycle. Having a package deployable from the command-line is closer to allowing some form of continous integration, too.

Tuesday, June 12, 2007

MOSS Internet Sites

I was preparing a list of MOSS public-facing web sites, but no point - 'cause here's a comprehensive list by Na-Young Kwon

Tuesday, May 29, 2007

Using Parameters in the SelectCommand of a Data View Web Part

The SelectCommand attribute of the SPDataSource element within a SharePoint DataView web part can use parameters supplied to the web part - and these parameters can come from a varity of sources, including the querystring in the page request.

This opens the way to easily control the data displayed in the data view; for example, via an ID supplied in the querystring.

The following code snippet shows some of the DataFormWebPart elements that use a value in the querystring to select a single list item to be displayed (the parameter is named SelectedRisk). Notice how the parameter is referenced in the SelectCommand:

<DataSources>

    
<SharePoint:SPDataSource runat="server" SelectCommand="<View><Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">{SelectedRisk}</Value></Eq></Where></Query></View>" ...>

        
<SelectParameters>

            
<WebPartPages:DataFormParameter PropertyName="ParameterValues" ParameterKey="SelectedRisk" DefaultValue="0" Name="SelectedRisk"></WebPartPages:DataFormParameter>

        
</SelectParameters>

    
</SharePoint:SPDataSource>

</DataSources>

<ParameterBindings>

    
<ParameterBinding Name="SelectedRisk" Location="QueryString(ID)" DefaultValue="0"/>

</
ParameterBindings>

Querying in CAML Relative to Today's Date

Found little information when searching for ways to perform date queries using CAML relative to today's date - only one reference to the use of OffsetDays from the article Customise the Content Query Web Part . Surprising the lack of information on this technique.

Here's the example from that article:

<Where>
  
<Gt>
      <FieldRef Name="Created" Nullable="True" Type="DateTime"/>
      <
Value Type="DateTime"><Today OffsetDays="-7"/></Value>
  
</Gt>
</Where>

Simple script to Remove and Redeploy a Feature

This script deactivates and deletes an existing feature, then redeploys this feature - it is useful when modifying features during development:


REM Add the 12 Hive bin folder to the path for access to STSADM
@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%

REM Configure local values
set siteURL=[site URL here]
set featureName=[Name of the feature]
set WSP=[Name of the WSP file, including the WSP extension]

REM Go to the folder containing the WSP file
cd [Full path to the folder holding the WSP file]

REM Remove the solution
stsadm -o deactivatefeature -name %featureName% -url %siteURL% -force
stsadm -o retractsolution -name %WSP% -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name %WSP% -override
stsadm -o execadmsvcjobs

REM Add the solution
stsadm -o addsolution -filename %WSP%
stsadm -o execadmsvcjobs
stsadm -o deploysolution -name %WSP% -immediate -allowgacdeployment
stsadm -o execadmsvcjobs
stsadm -o activatefeature -name %featureName% -url %siteURL% -force

Sunday, May 20, 2007

Changing the URL of a SharePoint Site Collection

Noticed that a site collection had a poor URL - to change the URL, backup the site and then restore using stsadm command-line operations:

To backUp:
stsadm -o backup -url {existing site collection URL} -filename {name of file}

To restore:
stsadm -o restore -url {new site collection url} -filename {name of file}

Thanks to Jose Barreto for saving me the task of rebuilding the collection from scratch

Thursday, May 10, 2007

Getting Users from Multi-select Person or Group Fields

The following code illustrates how to extract user information for all users listed in a multiselect Person or Group field (in this case extracting all the users listed in the "Control Owners" field of the first list item in the "Controls" list) :

using (SPWeb web = new SPSite(WEB_URL).OpenWeb())
{
    StringBuilder sb 
= new StringBuilder();    
    
SPList list = web.Lists["Controls"];

    
SPFieldUserValueCollection userVals = (SPFieldUserValueCollection)list.Items[0]["Control Owners"];
    foreach 
(SPFieldUserValue userVal in userVals)
    {        SPUser user 
= userVal.User;
          
sb.AppendLine(string.Format("{0}", user.LoginName));
    
}
}