Creating “Dynamic” XSL Variables

One of the really ugly things about working with Xsl is that it doesn’t support actual variables. There is a ‘variable’ element but it isn’t actually a variable; it is a constant as the value cannot be changed once it has been set. This leads to all sorts of horrible solutions, like duplicating Xsl for the various possible values/conditions or even turning a block of Xsl into a template and then passing parameters to it every time that value is needed. The latter works and is supported but is frequently overkill.

However, there is another way Click to read the full post

PowerShell Syntax Highlighting script

As a SharePoint administrator, I end up either writing a lot of PowerShell scripts or copying existing scripts and modifying them to fit a new need.  With all of these scripts comes the need to share them with other admins outside of the command line and in such a way that allows them to be easily Click to read the full post

Easily Allow Content Authors To Open Links as Dialogs

SharePoint 2010 introduces the new Dialog functionality that allows users to easily edit and update items from links on a page without having to leave that page; this works well and has a nice user experience.  The dialog functionality is primarily intended for use when editing list items or document properties, but I have had numerous requests to open other content (like news items) in dialogs as well.  This is relatively simple to do through JavaScript but does require a developer to be involved for each request, which is often time-consuming and expensive.  Ideally, there should be a way for the Content Authors themselves to specify which links open as dialogs and which do not.  Click to read the full post

Conditional Library References in Visual Studio

I recently ran into a situation where I needed to have a single project in Visual Studio build the application two different ways with each way using different DLL references. The normal Project Properties provide all sorts of mechanisms for build-specific options but Microsoft seems to have left the ability to specify conditional library references out of it for some reason.

It turns out that while they did leave it out of Visual Studio, it is available in MSBuild which Visual Studio uses to actually compile the code.

Here is how it works: Click to read the full post

Automatically Set the AssemblyFileVersion for Visual Studio Projects

One of the more annoying quirks with dealing with SharePoint is that once you develop a solution that requires custom code, all dependencies are then tied to the Strong Name of the compiled DLL.  That strong name also includes the version number, usually, and cannot be changed without breaking all existing references.  This is a good thing from a compatibility perspective but it does make it rather complicated to figure out exactly which version of a DLL is in use.

You can open up the WSP and then use the timestamps and take a guess at the version but it is not always reliable.  Click to read the full post

Bizarre Problem Using a Custom User Control as a Delegate

I was creating what I thought was a very simply custom user control to be deployed as a delegate in order to enable custom analytics on a SharePoint site.  Everything came together quickly and I deployed the solution via Visual Studio, reloaded the site but my custom control was nowhere to be found.

The custom control’s ASCX file is deployed to a subfolder of the CONTROLTEMPLATES folder as per best practices but no matter what I did the control would not load.  The ULS logs showed the theoretically simple “User control “~\_controltemplates\Analytics\FooterCalls.ascx” is not in safe control list.”.  I rechecked everything related to SafeControls, directories, features, activation and deployment but everything was as it should be.

It turned out that the problem had nothing to do with SafeControls but was actually in my Elements.xml file where I was activating the control as a delegate.  The line that was causing the issue was:

<control id="FormFooter" sequence="110" controlsrc="~\_controltemplates\Analytics\FooterCalls.ascx" />

This particular portion of SharePoint is apparently very sensitive to the direction of the slashes.  Changing them to forward slashes fixed the problem.

<control id="FormFooter" sequence="110" controlsrc="~/_controltemplates/Analytics/FooterCalls.ascx" />

Hopefully this will save someone the hours I spent tracking this less than obvious fix down.

Creating GUIDs in PowerShell

When you work with SharePoint, you end up working a lot with both GUIDs and with PowerShell. Strangely enough, the two together don’t seem to be needed very much but eventually their paths cross. GUIDs in PowerShell are amazingly simple to create but the web is chock full of misinformation and insanely complicated suggestions. I’ve even seen some folks recommend passing parameters to New-Object!

So, just for the sake of clarity, here is how to create GUIDs in PowerShell.  It really doesn’t get much simpler than this!

# Create an empty GUID

   $Id = [GUID]::Empty

# Create a new GUID

   $Id = [GUID]::NewGuid()

# Create a GUID with a value

   $Id = [GUID]("b2e92f11-7f65-41d1-acec-ba051b418bdf")

There’s nothing to it but some people choose to make this so complicated.

Update – 5/31/13 – I discovered a way to make it even simpler!