Silly DVWP, Grouping is for Kids

So I am working on a web part to aggregate some document libraries. I have created the Linked Sources record in SharePoint Designer 2010 and then grouped the document by the agg:source. Now the agg:source values have replaced the spaces in the library names with underscores. No problem. I update the Sort & Group with the following expression:

translate(../@agg:source,’_’,’ ‘)

Now “Section_125_Plans” displays as “Section 125 Plans” and so I am naturally pleased with myself and I check-in/publish only to discover that there is another issue. There is a library titled “401K Retirement Plan” which is being displayed as

agg:source cannot start with a number or it converts

agg:source cannot start with a number or it converts

I attempted to use the translate() function again, but it didn’t seem to help. Then it struck me…what if I open the page in SharePoint Designer and change the value of agg:source directly? After a bit of wandering I found the datasourcename parameter that matched “401K_Retirement_Plan” on the page.


Staring aimlessly for what seemed like an eternity, it suddenly occurs to me that the only problem seemed to be that the “401K” was being translated into “x0034 01K”. The DVWP grouping seemed to just not like the name of the source beginning with a digit. But it knew to translate the “_” to a ” “. Light bulb!

I put a “_” at the beginning of that datasource and wouldn’t you know it,
my grouping changed from “x0034 01K” to ” 401K”!!

Fixed Grouping beginning with a number

No more x0034 01K

Such a simple solution, but I thought I would share.

Thank you Powershell…

So we finally recently convinced the Program Managers and Project Managers that adding meta data to the document libraries on their programs.  Granted we had to have our Quality Management team scream to the moon that they couldn’t find specific artifacts that we needed for certification, but that is beside the point.  The agreed and even went so far as to give us some standardized categories for the documents – and yes the first bit were mostly just the names of the folders they were using.  The fun came up when I a realized that each project typically had 4-6 libraries.  With over two dozen active projects sites this meant I had well over one hundred libraries that I would need to either manually add the new DocCategory column.  Did I mentioned that there were new project sites being launch every couple of days?

Now this new column  was not going to apply to all document libraries, so i couldn’t just add it to the Document content type.  Sure it would be quick, but the number of emails and phone calls that would result would just bring out my evil twin Skippy and I would have to restrain him since I brought this all on my self.   So I made a new content type, added the new DocCategory column and a few site columns that would help further with Knowledge Management.  Then came the tough question, I do I get this into one hundred plus document libraries?  I loaded up my favorite search engine and found this article:

Adding a Custom Content Type to a document library with Powershell in Sharepoint 2010 by Gabriel Renom

This script worked great for the one library in each site that had the same name “Reference Documents”.  Plus there we a couple other things I want to make this script more useful in the future.  So I cracked open a couple of PowerShell books I have on my shelf and my favorite search engine and modified the script with the following:

  1. Removed the ContentTypetoBeDeleted – I just don’t need it for my process
  2. Use an array of Library names to speed up the process – otherwise I might as well do it by hand
  3. Only update libraries that the ContentType is not part of – I hate red error messages
  4. After adding the ContentType, make it the default of the library

The result is the following script

Function AddContentTypeToDocumentLibraryRemovingOtherContentType($_sCurrentURL,$_sDocumentLibraryName,$_sContentTypeToBeAdded) {
#Get site object and specify name of the library to look for in each site
$site = Get-SPSite $_sCurrentURL
$lookForList = $_sDocumentLibraryName
$ctName = $_sContentTypeToBeAdded
#Walk through each site
$site | Get-SPWeb -Limit all | ForEach-Object {
#Using the array of library names walk through each site and look for the library
foreach ($lookForList in $_sDocumentLibraryName){
#write-host "Checking site:" $_.Title "for" $lookForList

#Make sure content types are allowed on the list specified
$docLibrary = $_.Lists[$lookForList]

#Make sure the library exist
if ($docLibrary -ne $null)
$docLibrary.ContentTypesEnabled = $true

$MyLibraryContentTypes = $docLibrary.ContentTypes
#Make sure that the content types can be found
if ($MyLibraryContentTypes -ne $null)
#Make sure that the new contenttype is not already in the library
$ct = $docLibrary.ContentTypes[$ctName]
write-host "Content type" $ct.Name "already added to list" $docLibrary.Title "in" $_.Title
#Add site content types to the list
$ctToAdd = $site.RootWeb.ContentTypes[$ctName]
$ct = $docLibrary.ContentTypes.Add($ctToAdd)
write-host "Content type '"$ct.Name"' added to list '"$docLibrary.Title"' in" $_.Title
#Make sure that the new contenttype is the default in the Library
$currentOrder = $docLibrary.ContentTypes
$result=New-Object System.Collections.Generic.List[Microsoft.SharePoint.SPContentType]
foreach ($ct in $currentOrder)
if ($ct.Name.Contains($_sContentTypeToBeAdded))
$docLibrary.RootFolder.UniqueContentTypeOrder = $result
#write-host "The list" $lookForList "does not exist in site" $_.Title
#Dispose of the site object

Now when I load this into the PowerShell ISE i can call the function as follows:

$_CurrentURL = ""
$_DocumentLibraryName = "Project 10000.01 - SUPPORT SERVICES","Project 10000.01 - Secure","Project 10000.01 - Versioned","Project 10000.02 - SUPPORT SERVICES","Project 10000.02 - Secure","Project 10000.02 - Versioned"
$_ContentTypeToBeAdded = "Document - Projects"

AddContentTypeToDocumentLibraryRemovingOtherContentType $_CurrentURL $_DocumentLibraryName $_ContentTypeToBeAdded

The variables provide the Site Collection URL, the array of libraries I need to update and the ContentType I want to add to each library.  The example above took milliseconds to complete – a little longer before I commented out the ‘write-host’ commands.  In addition, since our project library names follow a pretty straight forward naming convention, I can create a pretty large array and have it run in the background, while I do other things.

Does this really make that much of a difference?   Couldn’t I have just pushed through and manually updated each library?  Well, yeah, but what fun would that have been?!?!  Plus, I just know I am going to need to use this PowerShell function again.  Hopefully, someone else out there will too.


Does your organization have a training plan

Jeff Cate has an  interesting  take on the need for training in this blog entry SharePoint is like a very complex swing set kit, but without the assembly instructions and picture.  Granted, he’s a professional trainer and in the end pushes the idea for in-person training.  That said, I like the comparison with a swing set kit, very clever.  Defintely worth a review.


Jquery Load a file Without Iframe. (via Web Development Tips by Team Indies)

This is brilliant! The Page Viewer is useful, but I always hate the fact that an over zealous power user could delete or modify the web part and then I start getting panicked phone calls.

What’s even better about this technique for me is that, according to the jQuery API, I don’t have to load the entire page. Imagine that! I create a page with multple charts and graphs in a central location and then I load only the one chart I want to on in the element.

Good stuff!

Jquery is a framework of Javascript. It is a well documented framework. I m just giving information about load a file in DIV or in anyother object HTML CODE here suppose you have no content in the given div and you want to load a content from another file like .html, .php or etc… so you can do this with jquery i have one file name is cleanupwizard … Read More

via Web Development Tips by Team Indies

Web Dev Tools I Can’t Work Without

I have been doing this ‘web thing’ since the mid-90s, (yeah I said 90s, look this is the Grumpy OLD Man’s SharePoint Blog, leave me alone!), and over time I’ve been accumulating tips, tricks and tools that always come in handy.  Some of those tools, like Bobby (HTML validation) have been replaced by more modern tools, and others have just improved over the years with new updates like NotePad++.

I love using ECMAscript,  jQuery, CSS and I am looking forward to incorporating W3C HTML5 with my SharePoint sites.  One thing though with client-side scripts, they can get big and complex and wiht the number of typos I make on a regular basis, I am just bound to have syntax errors.  So I have grown to appreciate the work of Matthias Miller on his impressive JavaScript Lint.  I know, I know I can use the IE9 Developer Tools and turn on JavaScript Errors.  Matthias made sure his tool is based on the JavaScript engine for the Firefox browser.  On more than few occasions, the Online versions has saved my tale from my poor typing.

Another handy tool is the Online JavaScript/CSS Compression Using YUI Compressor which allows you to compress ECMAScript and CSS.  Do you have to compress them?  No, but let’s face it, every ECMAScript and CSS file your client download is minified and why?  So you can speed up your client experience, of course!  Also, if your like me and work with a few SharePoint ‘power users’ who may be tempted to ‘tweak’ your work for their own nefarious designs, using this online tool, I don’t have to give my ‘you break it, you bought it’ speech.

One tool I miss InstantSource, and IE add-on that worked on IE5-IE7.  I realize many of the features are in IE9 Developer Tools, but the interface was really simple and easy to use.

So what utilities/tools do you use for Web Dev, whether online or offline?

SharePoint Saturday The Conference – DC 2011


OK, I suppose I could elaborate.

I started attending Wednesday evening last week.  Yeah, I know the conference did not officially start until Thursday morning, but some of us volunteers showed up Wednesday night to help stuff bags and setup for the other attendees, speakers, sponsors and exhibitors.  Now I have attended many conferences over the years, (Lotusphere 2001 was ridiculous with some 10,000 people and registration completely booked within 3 or 4 hours of registration opening), but this is the first time I have ever volunteered to help out.  It actually made the experience even better.   So many of the vendors and speakers volunteered as well, that I often got opportunities for private conversations and learn some really kewl stuff, (hey Matthew Bramer @iOnline247).  I will definitely signup to vounteer again.

In addition, there have been some amazing sessions, like SharePoint & jQuery – What I Wish I Would Have Known When I Started by Mark Rackley, aka ‘The SharePoint Hillbilly’.  Plus I have so much ‘swag’ from the conference, my wife is going to kick me out of the house!  I guess I’ll just have to hand some it out when I do my presentation ad SUGDC.  Speaking of which, we had a lot of folks stop by the SUGDC table right outside of the theatre.  Hopefully we will see more of these same folks at our SUGDC meetings in Reston, VA.  (Anyone else notice the shameless plugs for SUGDC?!?  Just checking).

Although it was a little up in the air on Saturday at the closing session, I sure hope we will have another SPSTCDC next year!  If you missed it this year, head over to SharePoint Saturday and look at the upcoming events.  If there isn’t one in your area, consider hosting your own!