How to download a WSP file from the Farm Solution Store

I’m following several migration projects during the last months, especially from SharePoint 2007 to SharePoint 2010, and of course I’m trying to stay within the standard approach as much as I can.

By “standard” I mean (roughly):

  • Premigration check
  • Deploy code customizations
  • Apply farm and webapp configurations
  • Perform a content database attach

This can be smooth or can be painful, especially during the last phase.

But… well, things can start to go wrong early, and unfortnuately not only during the premigration check.

For example, more than often we found a ton of wsps deployed, then ask our customer to provide us the wsp (the package, not necessarily the source code) and this fails with a sad “I don’t know where they are”. Or, which may be even worse, we get a different version of the package, which may or may not work as ecpected.

That’s why I wrote these 5 lines of PowerShell code that let us download the exact wsp package that is deployed.

This script is supposed to run on a SharePoint 2007 farm (that’s why I cannot leverage the commandlets included in the SharePoint 2010 PowerShell SnapIn).

Here it is:

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

$solution = $farm.Solutions[“nameofthewsp.wsp”]

$file = $solution.SolutionFile

$file.SaveAs(“c:\wsp\nameofthewsp.wsp”)

With some extra work, you could make this script iterate over all installed solution packages and, maybe, save them as a single zip file for convenience.

Discover unpublished files within a SharePoint web site

Here’s another small script that traverses a web hierarchy, seeking for files that are in a checked-out or unpublished (not approved) status.

function CheckPublishedFiles([Microsoft.SharePoint.SPFolder]$folder)

{

    foreach ($file in $folder.Files)

{

        $name = $file.Url

        try

        {

            $ok = (($file.Exists) -and ($file.OpenBinary() -ne $null));

            if ($ok)

           {

                $checkOutType = $file.CheckOutType

                if ($checkOutType -ne “None”)

                {

                    write-host “Checked Out: $name”

                }

                else

                {

                    $level = $file.Level                   

                    if ($level -ne “Published”)                   

                    {

                        write-host “Unpublished: $name”

                    }

                }

            }

        }

        catch

        {

            write-host “INVALID: $name”

        }

    }

    foreach ($subFolder in $folder.SubFolders)

    {

        CheckPublishedFiles $subFolder

    }

}

$web = get-spweb http://yourwebsite

$fld = $web.RootFolder

CheckPublishedFiles $fld

Discover corrupted files within a SharePoint web site

Although this is not exhaustive at all, since it uses a very simple mechanism to deem a file as corrupted (i.e. it tries to open it :-)), I found myself writing this little script and use it quite a lot of times.

Here it is:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

function CheckFiles([Microsoft.SharePoint.SPFolder]$folder)

{

    foreach ($file in $folder.Files)

    {

        $name = $file.Url

        try

        {

            $ok = (($file.Exists) -and ($file.OpenBinary() -ne $null));

            if (!$ok)

            {

                write-host “$name”

            }

        }

        catch

        {

            write-host “$name”

        }

    }

    foreach ($subFolder in $folder.SubFolders)

    {

        CheckFiles $subFolder

    }

}

$web = get-spweb http://yourweburl 

$fld = $web.RootFolder

CheckFiles $fld

DocIcon without links

You may face this issue and have your customers complain after a migration to SharePoint 2010 from any previous SharePoint version: the document icon is now displayed just as an image, without any anchor tag to redirect the user to the document stream.

There are several wasy to fix this issue. The one I like best, since it’s well integrated and it leverages one of the most useful SharePoint 2010 customization approaches, is available for download here.

As a quick reference:

Project Description

DocIcon for SharePoint re-enables links from document icons in SharePoint 2010. This feature was in previous versions of SharePoint, but was removed in the 2010, breaking the user experience for most sites. This feature should be considered required for all 2007 site migrations.

How It Works

DocIcon for SharePoint 2010 installs an XSL file in the /layouts/xsl folder that overrides the standard behavior of the docIcon field type. The solution deploys this file using a standard SharePoint solution built in Visual Studio 2010.

Extract Crawled Properties Mappings

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$searchapp = Get-SPEnterpriseSearchServiceApplication “Search Service Application Name Here”

$category = Get-SPEnterpriseSearchMetadataCategory –Identity “Category Name Here” -SearchApplication $searchapp

$properties = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category

foreach ($crawled in $properties)

{

$name = $crawled.Name

$managedProperties = $crawled.GetMappedManagedProperties()

foreach ($managed in $managedProperties)

{

$managedName = $managed.Name   

ac “c:\search.csv” “$name,$managedName”

}

}

I definitely love PowerShell 🙂

SharePoint 2010 AspMenu and UserSimpleRendering

This new Boolean property has been introduced in order let you opt for a more semantically correct HTML markup (no tables any more!). You get the option (which btw is set to false) because, of course, MicroSoft had to guarantee a backwards compatibility.

Just a small note: some of the properties of the menu (particularly, those which set the styles through ASP.NET styles) do not work on menus where UseSimpleRendering is set to false.

Developer Dashboard settings

Yes, you can find this almost everywhere (even within sites that talk about food or cars :-)), but anyway, I’m writingt here just for reference.

Here’s some line of PowerShell code that set how the Developer Dashboard is displayed:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$DevDashboardSettings = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;

$DevDashboardSettings.DisplayLevel = ‘***’;

$DevDashboardsettings.Update();

As a final note, remember that:

  • These settings are farm-wide
  • Having the Developer Dashboard “on demand” causes, at least in OOTB master pages, a small control to appear on the right upper corner of your pages. Which is fine (how would you launch the dashboard without some visual aid?) but sometimes can be painful: if you do not take care about this control beinig possibly there, you may end-up with a broken layout (imagine you have developed some custom master pages in an environment where the dashboard wasa off, then move everything into another environent where it is on-demand, and suddenly portions of your markup overflow… believe me, this may happen!!)