Category Archives: Development

Things not directly SharePoint related

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!

PNGs not quite right in Internet Explorer 8

I recently ran into a problem where PNG images were not being rendered properly in IE8, but only in IE8.  All other browsers displayed the images properly.  By “not being rendered properly” I mean that the PNGs were just slightly darker than the color they should have been, even though the image itself showed the proper color.  The the image below is an example of this; the left and right areas of the tabs are just slightly darker than the middle area.


At first I thought was related to the PNG transparency not being rendered properly and figured that I would take it up with the Graphic Artist when time allowed.  However, after walking away and then coming back to it, I was able to track down the real culprit: gamma correction.  It seems that the gamma information is included in PNGs to allow for a more accurate rendering of graphics, but that it is ignored by most browsers – except Internet Explorer 8.  A detailed explanation of the how and why of this can be found on Trevor Morris’s blog though his post was written prior to IE8, the issue was the same.

After spending some time in Paint.Net (I don’t have access to Photoshop) I was unable to come up with a way to remove the gamma from an image.  The Paint.Net forums suggested copying the image information into a new image and saving that, but that did nothing.  Fortunately, a bit lower in the same thread was the recommendation of a utility called “TweakPNG” and that did the trick.

All I had to do was simply save the image in my Image Editor, open it with TweakPNG, delete the gAMA information and hit Save.  Now my PNGs displayed correctly, even in IE8.


Debugging Powershell Modules in Visual Studio 2010

There are posts all over the web lamenting how difficult it is to debug a custom PowerShell Module from within Visual Studio 2010 but I found a simple way to do it that works every time.  It was tricky to get right at first, but this works like a champ.

Here are the steps:

  • Start Visual Studio
  • go the the Properties window for your custom Module Project
  • Select the ‘Start External Program’ radio button
  • enter “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” as the destination.  This will start PowerShell and attach the debugger to the instance


  • Go down to the “Start Options” and enter the text below in the “Command Line Agruments” box, including all of the quotes (naturally, you will have to change the paths for your project):

-noexit -command “& { import-module -name ‘C:\Path\To\Solution\Project\bin\Debug\CustomModule.dll’}”


This last step loads your custom module into the PowerShell instance that is being debugged.  From there, simply set your breakpoints in Visual Studio and then call your new PowerShell command from within the new PowerShell window.  It should stop on your breakpoint every time.

Happy Debugging!

Silverlight XAP File Out of Date When Built with Expression Blend


The latest project I am working on involves some rather tight integration between Silverlight and SharePoint so I'm getting my feet wet with these tools in the SharePoint-o-Sphere.

I recently ran into an issue where the .XAP file that is needed for Silverlight would not update properly whenever I built the solution within Expression Blend.  If I switched over to Visual Studio, then it would work perfectly.  A quick search showed no conclusive fix for this issue so I came up with this bute force workaround:

  1. Close Blend
  2. Open Visual Studio
  3. go to Project -> Properties -> Build Events and enter the line below in the Post-build event (replacing the web name as needed)

xcopy /y "$(TargetDir)$(TargetName).xap" "$(SolutionDir)sample.webClientBin"

After that, the build works fine in both Visual Studio and in Blend.

I should point out that when I initially created this solution the build worked fine in both Blend and Visual Studio.  The Blend build stopped updating the XAP file when I restructured the solution in order to put the projects into Team Foundation Server.  I cannot find anything in the folder structure itself that points to the old folders or structure so I am not sure where this behavior is coming from.