Friday, April 5, 2013

Removing Content Types and Site Columns from SharePoint

This blog post provides and documents a set of PowerShell scripts we developed to remove a set of content types and their associated site columns from a production SharePoint 2010 farm.

Often SharePoint will throw the exception "Content Type is still in use" when we try to delete a content type we no longer want.

Similarly, when we try to delete a Site Column, SharePoint will throw the exception "Site columns which are included in content types or on lists cannot be deleted. Please remove all instances of this site column prior to deleting it."

I recently helped a client remove a large number of content types as well as the site columns used in those content types from a production SharePoint 2010 farm on-premises. Library templates using these content types had been used extensively, so there were quite a lot of documents, libraries, and sites that all contained references to the content types and site columns. Surgically removing all these content types while leaving in place all the sites, lists, libraries and documents took quite some doing, so I thought I would share with you here some of the knowledge and PowerShell scripts that came from this experience.
 

Background


A SharePoint Content Types is a re-usable set of Site Columns, AKA fields. Content Types are defined in the Site Content Types Gallery in each Site Collection. Content Types are used in Lists and Libraries, as well as other places like workflows. SharePoint will prevent you from deleting a Content Type that is still referenced in a list or library in that site collection. Hence the exception "Content Type is still in use."

Site Columns are also defined in a Gallery in each Site Collection. Lists and Libraries can use these Site Columns directly - without referring to the Content Type. So SharePoint also prevents you from deleting a Site Column if there are any Lists or Libraries using that site column. It throws the exception, "Site columns which are included in content types or on lists cannot be deleted. Please remove all instances of this site column prior to deleting it."

This referential integrity can make it tough to delete a set of site columns and content types without deleting the documents and libraries that use them.  To work back through this chain of dependencies, we followed the sequence of steps listed below to delete content types and site columns from each site collection.

Sequence of Steps


For each step, we provide a link to the PowerShell script (provided on a separate page) that performs that action.

We started by making a list of all the Content Types to be deleted, specifying them in a simple XML file that is one input to the PowerShell scripts.

  1. Remove Content Types from all documents in all document libraries in the Site Collection by running RemoveContentTypesFromDocs.ps1
  2. Remove Content Types from all Libraries in the site collection by running RemoveContentTypesFromLibraries.ps1
  3. Remove Content Types from the Content Type Gallery in the Site Collection by running RemoveContentTypesFromSiteCollection.ps1
If RemoveContentTypesFromSiteCollection encounters exception "Content Type is still in use" you may need to use one of the following scripts which were developed to help locate places where a given content type is still in use within the farm:
Once all the content types are removed, you may start to remove the site columns.

Again, we created a simple XML file list of site columns to be removed

  1. Remove Site Columns from all Libraries by running RemoveSiteColumnsFromLibrariesOneSubsite.ps1 (which just processes one subsite, not the whole colleciton) or RemoveSiteColumnsFromLibraries.ps1 (which process the whole site collection)
  2. Remove Site Columns from the Site Columns Gallery in the Site Collection by running RemoveSiteColumnsFromSiteCollection.ps1
If SharePoint throws exception, "Site columns which are included in content types or on lists cannot be deleted," then run one of the following scripts to search out what Content Type, List or Library may still contain a reference to that site column:

How to Operate the Scripts

All the scripts have a syntax example in the comments near the start of the script.  All the scripts that operate on a site collection take the URL of the site collection as the first input.

The scripts that work with Content Types take, as input, the full pathname of an XML file that provides a list of all the content types to be found or removed.  The file ContentTypes.xml was used for this input file.

Similarly, the scripts dealing with Site Columns take, as input, the full pathname of an XML file that lists the names of all the Site Columns to be found or removed.  This file is named SiteColumns.xml and resides in the same folder as the scripts.

I hope these scripts are helpful and save you some time.

Thursday, November 15, 2012

Yammer or SharePoint 2013 or Neudesic Pulse for Social in 2013?


At the SharePoint2012 conference in Las Vegas, Microsoft showcased Social Computing in SharePoint 2013 and Yammer, and articulated vociferously their new-found commitment and enthusiasm for social as a central feature of intranets and pretty much everything else going forward.

This love-fest around social computing was dampened by the reality that Microsoft developed a set of Social features in SharePoint 2012 and then subsequently acquired Yammer. While the acquisition of Yammer underscores Microsoft's commitment to social, it muddied the waters leaving us with a distinctly cloudy and complicated message.
 
In a nutshell, that complex message seems to be that Yammer is the premiere social computing product that customers should use if at all possible, the Microsoft-developed social features in SharePoint 2013 are an alternative that may also be useful in certain circumstances, but pick one or the other: don't use both.

My clients are asking me which way to go, and I am working hard to synthesize a decision tree. Most of my clients embrace enterprise social computing and some need the kind of deep integration of Social features into applications that Yammer's Adam Pisoni was talking about at the SharePoint Conference 2012. (By deep integration I mean solutions for scenarios like deriving insight into customer needs or product development.) I don't have that decision tree worked out yet, but it is clear that they must choose one of three directions: 1) yammer if at all possible, the key  problem being if clients require hosting all data on-premesis, because the data in Yammer exists in the cloud. 2) social in SP or 3) a third-party product like Newsgator or Neudesic Pulse, which work fine in 2010.

Friday, September 21, 2012

Why Social Computing Really Comes to Life in SharePoint - 1


This series of posts explores the synergetic relationship between social computing and collaborative computing, with an in-depth look at several high-impact applications that leverage social computing features in SharePoint 2013.

I developed these applications and the attached PowerPoint presentation for SharePoint Saturday Redmond 2012.

So why does social computing really come to life in SharePoint? In a word, because it keeps the communication in context:

 
  • Successful social computing applications in SharePoint capture the communication between users in the context of the work they are doing.
  • It helps users keep track of people, keep track of work and keep track of the connections between them.
  • Social computing, done right, elevates teamwork to a whole new level.
  • It helps users find and get help from the experts, improving the traction and efficiency of the organization. And it can improve the overall quality of the work product
Why I Care

I have been developing collaborative applications since the early 1990s, starting with Lotus Notes, later with Groove, and now with SharePoint. I have followed the rise of social computing with great interest and healthy skepticism. What I see now is ample evidence that Social Computing can greatly increase the impact of many collaborative applications. The caveat is, l
ike everything in SharePoint, you have to do it right. 

Now, you may ask, “How can you say there is ample evidence that Social Computing is so great in SharePoint, when SharePoint 2013 hasn’t even been released yet?"

The answer is that social is nothing new to SharePoint. We’ve been building social applications in SharePoint since at least 2008. Companies like Neudesic and NewsGator have shipped Social products and deployed Social Apps in SharePoint with great success for years.

At Neudesic, we have been building compelling Social Computing apps integrated into SharePoint using our Pulse product. So I was extremely interested -- to put it mildly -- when, in July 2012, Ben Wilde demonstrated the SharePoint 15 Social Investments.
What immediately struck me, watching Ben's demo, was that the Social features in SharePoint 2013 look an awful lot like the Neudeisc Pulse in SharePoint 2010.
My reaction? Now that we have SharePoint 2013 in Beta, it validates what Neudesic has been doing all along. The social computing features in SharePoint 2013 bear such an uncanny resemblance to those in Neudesic Pulse that we must be seeing some kind of convergence. 

Pulse is the Social Computing product from Neudesic. Like corporate facebook, Pulse is a stand-alone product, but it integrates well with SharePoint 2010.

Analyzing Pulse in SharePoint 2010 side-by-side with Social in SharePoint 2013, I have come to the conclusion that the similarities far outweigh the differences. The biggest differences, in my analysis, are:
  1. Pulse has been shipping for 3 releases now
  2. Pulse works great in SharePoint 2010
  3. Pulse does not require My Sites, and
  4. You can use Pulse stand-alone (without SharePoint) if you like.
Pulse also has awesome iPhone, Android and Windows Phone apps:
 
So I set out to write these blog posts; not so much to compare and contrast Pulse with SharePoint, but rather to analyze what makes social computing work best in the context of SharePoint applications. With my deep experience building collaborative software, my inside knowledge of Pulse, and my professional expertise in SharePoint, I feel uniquely qualified to convey my answers to the following key questions:
  1. What are the key features behind successful social computing in SharePoint?
  2. What are the high-impact applications where social really works? And
  3. How can I build these high-impact applications – either in SharePoint 2010 or in SharePoint 2013?

Let's start by looking at the technical elements that make the integration of social into SharePoint successful. Later I will demonstrate how, using these elements, to build compelling SharePoint applications that leverage social computing.

The Nuts and Bolts of Social Computing


These are the building blocks -- the core, Facebook-inspired features -- that are the nuts and bolts of social computing.

Micro-blogging
Micro-blogging is at the heart. You can read, post, and reply. The result is a threaded discussion; When merged with other threads we sometimes call this an activity stream.

Follow

What does it mean to Follow? To Follow an activity stream adds that stream to your newsfeed

In SharePoint 2013, you can follow:

  • People
  • Documents
  • Sites
  • Tags 
In Pulse in SP 2010 you can follow:
  • People
  • Posts
  • Groups
  • Tags
  • Systems
In Pulse, follow also creates a bookmark (“People followed by me”)

Liking and Mentioning

Both Liking and Mentioning create connections. You get a notification in your E-mail each time someone mentions you in a post.

Tagging and Rating

Tagging and Rating (or voting) are both a bit like democratic bookmarking. You use tags and votes to find stuff later.

 E-mail

Speaking of Mentioning: don’t forget E-mail! The E-mail in-box remains so deeply entrenched you cannot succeed without robust email integration. Notifications go to your inbox each time someone mentions you in a post. The E-mail contains a link back to the Activity Stream. This drives people back into the social tool which is good. As much as we all wish E-mail would become obsolete, it is not. It’s entrenched. It’s the boat anchor. Your social solution must integrate with E-mail or forget it.

So what kinds of collaborative applications really shine when enriched with social features?  And how do I create great social + collaborative applications now that we have such a rich tool chest to work with?
Four High Impact Social Computing Apps in SharePoint

Here's my short list of high-impact social computing applications in SharePoint:


Team collaboration around developing a document or presentation

A typical scenario for this application is when a sales or account team needs to collaborate around developing a response to an RFP. 

A well-designed team collaboration application focuses the social discussion on the document, doc set, or other work product that the team is developing. Your key design point for this kind of application is to present the work-product content as close to the discussion as possible.

Knowledge base -- or forum -- where community members vote on, or rate, documents, answers or posts

Knowledge management experts know the value of end-user feedback to refine, or filter a corpus of knowledge.  

The design point of a knowledge base, or forum, is to harness the knowledge of your people, leveraging that wisdom to cultivate and continuously refine the repository of content. The feedback must be leveraged to sort views and rank search results so that others can find the best, most useful stuff right away.


KPI dashboard where metrics are enhance by discussion; group leaders and members discuss and act on results


SharePoint has long been a great platform for Business Intelligence (BI) dashboards. Now social features only make that better.

Your key design goal for applications like this is to give dashboard users immediate access to the people who are responsible for the business or the process that the metrics are measuring.  Managers need to be able to ping a team member and ask why a certain KPI has turned red. If you are the one responsible for a certain outcome, you want to be able to post a comment that lets everyone (like your boss) know that you are aware of the metric, and you know what your team is doing about it.

Expertise Finder: Identifying and getting help from co-workers who have specific knowledge

I rarely see a specific application created for finding experts. Rather, finding expertiese is implemented by making sure Search includes detailed, up-to-date user profiles. 

Enterprises realize significant value from the ability to find co-workers who have specific knowledge.  While this may well be the most important app on my short list, it often comes for free as a by-product of a truly collaborative corporate culture.

The key elements of expertise finder are:
  • broad user adoption and participation in social technologies
  • detailed user profiles
  • effective search
In subsequent posts, we'll examine actual implementations of some of these applications, mostly using SharePoint 2013. We'll give screen shots and instructions for how to build these apps using out-of-the box features available in SharePoint 2013. 
 

Monday, August 6, 2012

My speaker session has just been accepted for SharePoint Saturday Redmond 2012. I'll be speaking on "Why Social Computing Really Comes to Life in SharePoint". The event occurs on Saturday September 22, 2011. I plan to blog most of my material here first. Here is the abstract for my session:

Social computing adds a whole new dimension to collaboration platforms like SharePoint. Tagging, Following and Microblogging, when integrated successfully into SharePoint, can really bring your web applications to life. The right integration of social computing increases the impact of your business application by plugging them in to the power of teamwork.

The new social computing features Microsoft has introduced in SharePoint 2013 closely mirror and validate the approach of earlier third party social computing applications such as Neudesic Pulse.  This presentation will reveal what approach both Microsoft and Neudesic took to integrating social with SharePoint, and what makes that approach so successful.  We will look, in-depth, at high-impact applications that leverage social computing features integrated into SharePoint.


This session is not a Pulse sales pitch, nor will it simply compare-and-contrast SharePoint 2013 with Pulse. Rather, we will pinpoint the common features of both Pulse and  SP2013 that make social computing in SharePoint a synergetic relationship. We will look at the web parts, service apps and other technical elements that make this integration so successful and demonstrate how, from a solution developer's perspective, to design compelling applications that leverage those elements.


I hope to see you there!

Tuesday, June 12, 2012

I will be delivering my demo and presentation on The Art and Science of the XSLT List View Web Part at Seattle Code Camp 2012 this Saturday, June 16, 2012 in Redmond.

Friday, May 18, 2012

XSLT List View Web Part Best Practices, part 3

This is the third post that follows the presentation I gave to the Puget Sound SharePoint Users Group on May 17, 2012.

Parts 1 and 2 of the XSLT List View Web Part Best Practices described a procedure that sets you up with a Visual Studio Solution and a known-good XSLT file derived from SharePoint.

The benefits of this setup are two-fold:
  • You can edit your XSLT in Visual Studio 2010. For any large XSLT file, Visual Studio is the right place to edit your XSLT, particularly when the rest of your project is in Visual Studio.  Visual Studio gives you intellisense, syntax color-coding, and more importantly, a robust environment that respects your source code as sacred. SPD sometimes does funny things to your files.
  • You can iteratively deploy and test your XSLT in-situ meaning,  in place in SharePoint where it's really going to run in production. There are scores of great XSLT development tools on the market but none of them seem to understand the SharePoint-specific quirks of XSLT developed to run inside an XSLT List View Web Part.

This post describes a PowerShell script that automates the key step of uploading the XSLT file you are editing in Visual Studio to the Style Library of your test site in one click. This script streamlines the process so you can edit-upload-test in a tight iterative cycle in order to really do your XSLT development inside SharePoint.

Recall from part 2 that we configured the XSLT List View Web Part to use the "SpotNewsStyle.XSLT" file located in the Style Library.  We did this by editing the web part properties and setting the XSL Link field to point to our custom XSLT file in the Style Library. This means we can iteratively tweak our XSLT file, upload the XSLT file to the Style Library, and test by just refreshing the browser.  This faster, less invasive and safer than editing the web part every time. The PowerShell script below reduces the already quick process of uploading the XSLT file to the Style Library to one click.

The LoadStyle.ps1 script


The LoadStyle.ps1 script below (part of the sample "Spot" solution available here) is designed to reside in and be run inside the "Deploy" folder of the "Spot" Visual Studio solution. You will certainly need to edit this file to make it work in your environment. However, the changes you need to make should be obvious and straightforward. This script has the name and relative path to the custom XSLT file (SpotNewsStyle.xslt) and Css style file (SpotStyles.css) hard-coded. It copies those two files from where they reside to the current working directory.  It then opens my test SharePoint server at the hard-coded URL http://vm01  and uploads both files to the Style Library.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction
    "SilentlyContinue"
Start-SPAssignment -Global

Copy-Item ..\StylesAndScriptsModule\SpotNewsStyle.xslt . -Force
Copy-Item ..\StylesAndScriptsModule\SpotStyles.css . -Force
$spWeb = Get-SPWeb -Identity
http://vm01/sites/spot/
$spFolder = $spWeb.GetFolder("Style Library")
$spFileCollection = $spFolder.Files
$xsltFile = Get-ChildItem -LiteralPath $(Get-Childitem SpotNewsStyle.xslt)
$xsltFileStream = $xsltFile.OpenRead()
$spFileCollection.Add(

    "Style Library/XSL Style Sheets/SpotNewsStyle.xslt",
    $xsltFileStream, $true)
$xsltFileStream.Close()
$xsltFile.Delete()
$cssFile = Get-ChildItem -LiteralPath $(Get-Childitem SpotStyles.css)
$cssFileStream = $cssFile.OpenRead()
$spFileCollection.Add("Style Library/SpotStyles.css", $cssFileStream, $true)
$cssFileStream.Close()
$cssFile.Delete()
Stop-SPAssignment -Global

After uploading to the Style Library, it deletes copies of the files that it created in the current working directory.  It does this so you can run this script over and over and it will always get the latest new version from the Visual Studio directory.

The Development Process

With all these pieces in place, you may iteratively develop your XSLT file by:
  1. In Visual Studio, edit your custome XSLT file and click "save"
  2. Switch tasks to your SharePoint Management Shell (PowerShell) and run the LoadStyle.ps1 script shown above.
  3. Switch task to your browser which should already have your SharePoint site open with the page that has the XSLT list view web part displayed.
  4. Press F5 to refresh the browser.
The Web part re-reads the newly uploaded XSLT list view and renders to your browser. This process seems less integrated than the Visual Studio F5 debug button but it's actuall much faster (Your browser can already be running - - no need to launch IE) eliminates a whole set of issues associated with Visual Studio trying to "compile" your XSLT.

Conclusion


When you are developing XSLT for the SharePoint XSLT List View Web Part, you really only need to save your file, upload it to the Style Library, and refresh your browser in order to test it.  These blog posts described how to streamline your development process to the bare essentials freeing you to repeatedly code-and-test iteratively in the most efficient manner possible.  I hope it helps. <MC>

XSLT List View Web Part Best Practices, part 2

The Art and Science of the SharePoint XSLT List View Web Part (part 2)

This is the second post that follows the presentation I gave to the Puget Sound SharePoint Users Group on May 17, 2012.

This (part 2) blog goes in detail through the best practices I mentioned in the "procedure" summary in yesterday's post.  For reference these best practices are listed below and described more step-by-step in the rest of this post:

Best Practices (Summary)

  1. Lay the Groundwork
  2. Obtain the Known-Good SharePoint XSLT file. This becomes your Custom XSLT File.
  3. Create a "Deploy" Project Folder in Visual Studio but outside your SharePoint Solution
  4. Upload your Custom XSLT File to your Style Library and set the XSLT Link Property of your XSLT List View Web Part to point to it.
  5. Create a LoadXSLT.ps1 script that loads your custom XSLT file to your Style libraray with one click

1. Lay the Groundwork

Before we get to the XSLT, we need to lay the groundwork. The goundwork consists of:
  1. Create a SharePoint site where you will do your development work, e.g. /sites/spot
  2. Create the Visual Studio Solution
  3. Add Site Columns
  4. Add a Content Type
  5. Add List Definition from Content Type
  6. Modify the List Schema to make the default view contain all the important columns
The above steps are pretty much cut-and-dired SharePoint development so I won't go into detail. The finished "News and Announcements" list is available as the "Spot" sample solution at the drop box location above. The list provides the data but not the visual presentation we need.

2. Obtain a Known-Good SharePoint XSLT file using SharePoint Designer 2010

Obtain a Known-Good SharePoint XSLT file using SharePoint Designer to “harvest” the XSLT of your List View. This is an extremely valueable trick:

Use SharePoint Designer 2010 to Add the XSLT List View Web Part to the site home page.



  1. Open the Site in SharePoint Designer
  2. Under Customization, click Edit site home page asd;lfk
  3. SharePoint designer displays the Home.aspx page in Design mode. Click in the center or wherever you want to put the News and Announcements web part.
  4. Select the "Insert" tab on the SharePoint Designer Ribbon.
  5. Select the "Data View" button on the "Insert" ribbon. This will display the lists and Document Libraries available:
  1. Select the News and Announcements  list we previously created.SharePoint designer adds the WebPartPages:XsltListViewWebPart  to the page
  2. Choose split view to see the markup <WebPartPages:XsltListViewWebPart>


Now "Harvest" the XSL created by SharePoint from this new web part

Still in SharePoint Designer 2010, click the "Design" tab in the ribbon
In the "Actions" section of the ribbon (towards the right) click "Customize XSLT"
SharePoint Designer displays the markup for the web part including the <xsl> element that defines the full XSLT markup used by the web part.




  1. The "Customize XSLT" ribbon button displays a couple of choices. Select "Customize Entire View".    SharePoint Designer expands the entire XSLT into the Code pane.
  2. Select code in SharePoint Designer to view the complete markup of the web part.
  3. You want to copy the XSLT part of the and save it on disk so that you can add just that file to the "Spot" solution.
  4. Find the <xsl> element that marks the start of the stylesheet. This will be some 10 lines down. The start will look like this:
  5. <xsl>
      <xsl:stylesheet xmlns:x=http://www.w3.org/2001/XMLSchema
  6. Copy everything between the <xsl> starting tag and the </xsl> closing tag, not inclusive.  There will be a lot. Copy to your clipboard.

3. Create a "Deploy" Project Folder in Visual Studio

Paste the XSLT you have in your clipboard into a new file in your Visual Studio Solution as follows:

    1. Open your Visual Studio solution
    2. Add a new Project Folder called "Deploy" that is OUTSIDE the SharePoint project
    3. In the "Deploy" folder, create a new file of type "XSLT" called, e.g. SpotNewsStyle.xslt
    4. Paste the XSLT from your clipboard into this XSLT file.
Your SpotNewsStyle.xslt file should start with <xsl:stylesheet> and end with </xsl:stylesheet>

4. Upload your Custom XSLT File to your Style Library and set the XSLT Link Property of your XSLT List View Web Part to point to it.
      Manually upload your XSLT file to the Style Library in your site
      While developing your XSLT, you may short-cut the SharePoint <deploy> or F5 step and simply edit the XSLT file in Visual Studio, then upload the file to the Style Library of the site and refresh the browser:
      1. Open your Site in IE
      2. Site Actions --> View All Site Content
      3. Select Style Library from the list of Document Libraries
      4. To conform with convention, create a new folder named "XSL Style Sheets" in the Style Library if your library does not already have one. Do this in the Style Library by clicking "Documents" in the ribbon.  Click "New Folder" in the Ribbon. Name the new folder "XSL Style Sheets".
      5. Open the XSL Style Sheets Folder.
      6. Click Add Document.
      7. In the "Upload Document" dialog, click Browse… and navigate to the project folder (\StylesAndScriptsModule) where you saved your SpotNewsStyle.xslt file.
      8. Select your SpotNewsStyle.xslt file and click Open.
      9. After your XSLT file is uploaded to your Styles Library, right-mouse-click on the new file and copy shortcut so you have the full and correct path on your clipboard for the next step.

      Set the XSL Link Property of the XSLT List View Web Part to point to your custom XSLT
      1. Open the home page of your Site in IE
      2. Edit the page
      3. From the Web Part Properties menu select Edit Web Part
      4. SharePoint displays the properties of the XSLT List View Web Part on the right
      5. In the Properties pane, scroll down and expand the "Miscellaneous" section
      6. In the field marked XSL Link , PASTE or enter the path to the SpotNewsStyle.xslt file you stored in the Style Library:



  1. Click OK

  1. Save your edits to the page.
The benefit of this arrangement is that you will not have to re-edit this home page while editing the XSLT file. All  you have to do is upload your edited XSLT file to the Style Library then refresh the home page and it will render the XSLT if it can.

The next post will describe a PowerShell script that automates this step of uploading the XSLT file to the Style Library in one click.  This streamlines the process so you can edit-upload-test in a tight iterative cycle in order to really do your XSLT development inside SharePoint.