Wednesday, August 10, 2011

Getting SharePoint Feature IDs (the easy way)…

 

So I needed to grab the id of a feature so that I could programmatically activate it during a site / web provision process.  Google gives me a couple of lists with the standard features and ids.  It also tells me I can do a file contents search against the features directory once I’ve obtained the resource key from the global resources file (eek).

I wondered that, if in like rendering an OOB new/edit/display form, the SharePoint Developers at MS put the info I needed hidden in HTML?

Sure enough – the corresponding feature id is there as the ‘id’ of the div surrounding the button (input) element:

image

(Obviously, this only works for features that aren't hidden)

Thursday, August 4, 2011

Programmatically Enumerating Databases in SharePoint 2010

See below -

using (SPSite site = new SPSite(url))

{

    using (SPWeb web = site.OpenWeb())

    {

        SPFarm f = site.WebApplication.Farm;

        foreach (SPDatabaseService s in f.Services.OfType<SPDatabaseService>())

        {

            Console.WriteLine(string.Format("Found Database service {0} of type {1}",

                s.Name, s.GetType().Name));

            foreach (SPDatabaseServiceInstance spdsi in s.Instances)

            {

                Console.WriteLine(string.Format("|-Found Database Service Instance {0} ({1})",

                    spdsi.DisplayName, spdsi.Name));

                foreach (SPDatabase spdb in spdsi.Databases)

                {

                    Console.WriteLine(

                        string.Format("  |-DB: {0}\r\n    |-TYPE: {1}\r\n    |-HOST: {2} ",

                        spdb.Name.Length > 70 ? spdb.Name.Substring(0, 65) + "..." : spdb.Name,

                        spdb.GetType().Name, spdb.Server.Name)

                        );

                }

            }

        }

    }

}

Results look something like:

image

Breadcrumbs in SharePoint 2010

(That don’t require a click)

 

One of the biggest surprises I came across in moving to 2010 was the lack of breadcrumbs?!

I came across a few articles that explained/showed how you could enable v3 based controls to show – but these didn’t work on all pages.

Anyway, without spending hours of time testing – try this:

  1. Add reference to jquery (Master Page Edit, Control Delegate or inline content editor web part)
  2. Add the following Javascript (again – via a master page edit, control delegate or inline content editor web part)


$(document).ready(function () {
    $('table.s4-titletable > tbody > tr').append('<td id="crum"></td>');
    $('td#crum').html($('.s4-breadcrumb').html());
    $('td#crum li > span > span > img').first().css('top', '');
    $('td#crum span.s4-breadcrumbCurrentNode').css('font-weight', 'bold');
    $('td#crum span.s4-breadcrumbCurrentNode').css('color', 'gray');
    $('td#crum').css('white-space', 'nowrap');
    $('td#crum li').css('padding-right', '2px');
});

 

You should get a result similar to below:

(Yes, they are clickable / functional and completely dynamic)

image