Joel's SharePoint Architect Blog

SharePoint 2013 Training, Architecture, Administration and Development

Subscribe Subscribe  View Joel Jeffery's profile on LinkedIn
joelblogs.co.uk | joelj.co.uk | joeljeffery.co.uk | jfdiphoenix.co.uk

Posts Tagged ‘SharePoint 2010’

This question was asked by one of my (most excellent) students this week:

In an ASP.NET Web Part for SharePoint, when I override CreateChildControls(), do I need to invoke the base?

You will see many examples on the Internet of code that does invoke the base, and many counter examples. Some of these contradictory examples are on the Microsoft MSDN site!

I decided to take ILSpy to the System.Web.dll assembly and find out once and for all.

First of all, System.Web.UI.WebControls.WebParts.WebPart does not override CreateChildControls() itself.

System.Web.UI.WebControls.WebParts

So, we must take a look at it’s ancestor: Part.

System.Web.UI.WebControls.WebParts.Part

Once again, there is no implementation for CreateChildControls() here, so we go further up the chain to System.Web.UI.WebControls.Panel:

System.Web.UI.WebControls.Panel

Still no definition of CreateChildControls(). Further up, we get System.Web.UI.WebControls.WebControl.

System.Web.UI.WebControls.WebControl

But it is not until we get to System.Web.UI.Control that we have an implementation:

System.Web.UI.Control

Hang on a moment! That’s empty!

// System.Web.UI.Control
/// <summary>Called by the ASP.NET page framework to 
/// notify server controls that use composition-based 
/// implementation to create any child controls they contain
/// in preparation for posting back or rendering.</summary>
protected internal virtual void CreateChildControls()
{
}

So, the simple answer appears to be:

No, you don’t need to invoke base.ControlChildControls() in an ASP.NET WebPart”

Technorati Tags: ASP.NET, Development, SharePoint 2010, SharePoint Development

Updated SharePoint 2010 Google Maps Web Part (v1.2)

There’s an updated version of the SharePoint 2010 Google Maps Web Part available for download here: http://sp2010googlemaps.codeplex.com

We’ve fixed a bug with multi-line labels. :o)

Works on-premise, in the Sandbox and in Office 365.

Technorati Tags: Development, Office 365, SharePoint, SharePoint 2010, SharePoint Development, Solution Sandbox

SharePoint Documentation Kit (SPDocKit)

I need to tell you about something fantastic.

SharePoint Documentation Kit – SPDocKit Review

I’ve been using SPDocKit from Acceleratio for about 6 months now, on and off. One of the services we offer at JFDI Phoenix is our SharePoint 2010 Farm Health Check, and this involves a lot of boring navigation through Central Admin and some gnarly PowerShell to gather farm insight. Collecting settings information by hand is tough and time consuming.

The value-add for customers comes from what I can deduce from their configuration – what problems they’ll see; whether their platform will scale; whether it will be secure enough.

SPDocKit helps me gather the vast majority of the information I need, and formats it into a very detailed, very useful report in Word format.

Here’s just a snippet from the table of contents:

SPDocKit Table of Contents

It goes on to produce a detailed inventory of each server in the farm:

Farm Overview

It even builds a Visio-style diagram showing the farm topology. OK, I know it looks daft when I run it on a one-server farm, but it is vastly more impressive on a multi-server farm!

Farm Topology

It also identifies and lists:

  • Services on server, per server
  • Site topology (site collections per web application)
  • Web applications
  • Self-service site creation settings
  • Alternate access mappings
  • IIS settings
  • Site collection usage
  • Quota templates
  • Service applications
  • Detailed settings for each application
  • Databases used
  • Permissions
  • Associations to web applications and proxy groups
  • Content databases, usage and quotas
  • System settings, including email and SMS settings
  • Features and solutions
  • Sandbox configuration
  • Monitoring and reporting
  • Security
  • Administrators
  • Managed accounts
  • Service accounts
  • Products and versions
  • Scheduled tasks
  • Server information
  • Hardware / cores
  • Installed programs and hotfixes
  • Drives and free space

If this wasn’t enough, it also lets you record all this information and monitor changes over time.

More Features!

And there’s more! The SPDocKit application itself has a pretty useful UI. You can browse the web application and site structure without needing to generate documentation:

Site Explorer

It also lets you walk the permissions of your sites. Very useful if you’ve been breaking inheritance and you want to know who has access to what. Having said that, SharePoint’s built-in “Check Effective Permissions” button is still invaluable to debugging permissions problems.

Permssions Explorer

There’s also a Detailed Permissions report, but this is still a very interactive tool:

Detailed Permissions

There’s even best practices analysis built in:

Best Practices

Although obviously not exhaustive, it does give a very good start for a more detailed analysis of a farm.

There’s also a Scheduled Tasks viewer:

Scheduled Tasks

Conclusion

Whilst SPDocKit is not magic, it certainly saves me a great deal of time on SharePoint farm health checks. The licensing is pretty cool also. You can either buy it for an individual farm, of have a yearly subscription as a consultant. If you’re using the latter, the setup exe lets you run it on a server without leaving it installed afterwards.

Technorati Tags: SharePoint 2010, SharePoint Administration, SharePoint Architecture

A while ago, a student of mine asked if it was possible to use the taxonomic alternative labels from the Managed Metadata Service as thesaurus items in SharePoint Server Search.

There’s no built-in way to do this, but it is possible to generate the required Xml with a little PowerShell.

The Concept

The Term Store contains Term Group, which content Term Sets, which in turn contain nested Terms. Each Term can have (optional) synonyms called Labels.

If we find all the Terms with Labels, we can write them out in the correct format as a chunk of Xml, and pipe it into a thesaurus file.

Thesaurus files for SharePoint Server Search are kept under the file path:

%ProgramFiles%\Microsoft Office Servers\14.0\Data\Office Server\Applications\GUID-query-0\Config

A sample thesaurus file is shown below:

<XML ID="Microsoft Search Thesaurus">
    <thesaurus xmlns="x-schema:tsSchema.xml">
        <diacritics_sensitive>0</diacritics_sensitive>
        <expansion>
            <sub>Internet Explorer</sub>
            <sub>IE</sub>
            <sub>IE8</sub>
        </expansion>
        <replacement>
            <pat>NT5</pat>
            <pat>W2K</pat>
            <sub>Windows 2000</sub>
        </replacement>
    </thesaurus>
</XML>

You can see the rationale for how this file works on and how to manage thesaurus files at TechNet.

The Script

The script below shows the principle. It iterates over the Terms in each Term Store and finds their Labels. Where the Label is not the same as the name of the Term itself, it represents a synonym and we add it to the Xml.

function Extract-SPThesaurusFromTermLabels
{
  param([string] $webUrl);
  $ts = Get-SPTaxonomySession -Site $webUrl;
  Write-Output "<XML ID='Microsoft Search Thesaurus'>"; 
  Write-Output "<thesaurus xmlns='x-schema:tsSchema.xml'>"; 
  $ts.TermStores | 
  % { $_.Groups | 
    % { $_.TermSets | 
      % { $_.Terms | 
        % { $_.Labels | 
          ? {$_.Term.Name -ne $_.Value} |
          % { 
            Write-Output ("<expansion><sub>" + $_.Term.Name + 
              "</sub><sub>" + $_.Value + "</sub><expansion>");
          } 
        } 
      } 
    } 
  }; 
  Write-Output "</thesaurus>"; 
  Write-Output "</XML>";
}

You can then pipe the output of this command to an Xml file, and optionally use this in the place of your existing Thesaurus file with something like this:

Extract-SPThesaurusFromTermLabels http://sharepoint > tsLANG.xml

As always, please back up your original Thesaurus files and check the output of this before you use it! Smile

Technorati Tags: PowerShell, Search, SharePoint, SharePoint 2010, SharePoint Administration, SharePoint Administrator

SPSite and the Recycle Bin in SharePoint 2010 SP1

Service Pack 1 for SharePoint 2010 brought us a much-needed feature – the recycle bin for SPWeb and SPSite objects.

Recycling SharePoint Sites

If you want to move an SPWeb into the recycle bin programmatically, there’s the fairly-straightforward SPWeb.Recycle() method. Once you’ve invoked this, you can restore the SPWeb from the SPSite.RecycleBin object with the Restore() method.

But, how do I recycle and restore a site collection (SPSite)?

Recycling SharePoint Site Collections

Firstly, there’s no Recycle() method on the SPSite object. Invoking Delete() removes the SPSite immediately, unless you pass in an argument to get it to perform a gradual delete. The gradual delete process is carried out by the “Gradual Delete Timer Job”, whose purpose is to delete site collections efficiently 1000 database rows at a time.

However, it also has some nice side effects. The timer job only deletes site collections that were deleted more than 30 days ago (or whatever the recycle bin age is configured for the web application). In that intermediate time, the deleted site collections are available to be restored.

You can get at the deleted sites via the GetDeletedSites method of the SPWebApplication object. This returns a collection of SPDeletedSite objects, on which you can invoke the Restore method.

Sample Code

// get our web application
SPWebApplication webapp = SPWebApplication.Lookup(new Uri("http://sharepoint"));
// find our deleted site collection
foreach (SPDeletedSite site in webapp.GetDeletedSites("http://sharepoint/sites/myoldsite"))
{
    //restore it!
    site.Restore();
}

Enjoy!

Technorati Tags: SharePoint, SharePoint 2010, SharePoint Development