views:

754

answers:

10

Like the other "Hidden Features" questions, what are your favourite parts of the SharePoint API and development platform (both WSS 3.0 and MOSS 2007) that help you get the job done?

Please share your tips, tricks and secrets!

+6  A: 

Here are a few of my favourites:

  • SPUtility.Redirect with the SPRedirectFlags.DoNotEndResponse flag. Avoids ThreadAbortException for you without the need to clutter your own code.

  • SPUrlExpressionBuilder. This class allows you to build dynamic URLs using tokens such as ~site, ~sitecollection, ~language.

  • SPContext.Current.Web.CurrentUser. Simply does what it says on the tin.

  • Microsoft.SharePoint.SPBuiltInFieldId. STOP!! If you ever find yourself hardcoding a GUID (e.g. updating the DataTable in the ProcessItems method, Content Query Web Part). You'll find it in this class.

Alex Angas
+2  A: 

My Favourite feature would have to be delegate controls.

The idea is that you can replace the standard sharepoint controls with your own user controls. The normal feature deployment process can be employed, so you can easily deploy and retract your changes, but most importantly you don't touch the SharePoint system files.

The delegate control is normally used to help brand the SharePoint site or to provide alternate functionality.

A good example can be found here

Daniel Pollard
+5  A: 

My favorite feature (though it isn't an API object) is "feature stapling". Being able to automatically attach and activate a feature based on the site template being used. This is great for swapping out the MasterPageUrl.

As far as API I would have to say the SPSite overload that accepts a user token.

SPUserToken systemAccountToken = SPContext.Current.Site.SystemAccount.UserToken;
Guid siteGuid = SPContext.Current.Site.ID;
using(SPSite site = new SPSite(siteGuid,systemAccountToken))
{
     //...do something
}

This is the prefered way to elevate privledges unless you require network access rights.

webwires
+1  A: 

SPEmailEventReceiver class. Allow e-mail enable lists like Contacts that don't have this ability out of the box.

Dmitri Kouminov
have you made any custom email handlers?
Kevin Davis
Yes. I did it for contact list
Dmitri Kouminov
+4  A: 

Custom Provisioning Providers SPWebProvisioningProvider

They let you do stuff on a site after it has been provisioned.

Feature stapling can cause race conditions since you in some situations cannot be sure if an artifact is provisioned or not (stapled features are executed in random order inside their scope)

Also provisioning providers only need a new template ID in webtemp, so its a pretty clean approach!

Anders Rask
A: 

Custom Search Results pages - not really hidden, but very powerful, and frequently overlooked. You can really improve the results pages with a bit of XSL and a few changes to the Core Results web part.

If I had to select a class, though, I'd nominate the `SPSiteDataQuery' (MSDN)

Andy Burns
A: 

Making schema.xml View elements concise by referencing all the guff using

<ViewStyle ID="0" />

or

<ViewStyle ID="17" />
Michhes
+2  A: 

It has to be SPSecurity.RunWithElevatedPrivileges(delegate).

There are plenty of bits of the SharePoint API that I am not a big fan of, but this one makes me feel quite dirty every time I use it. But I often use this to wrap all of my Data Access code so that I can use Integrated Authentication.

private DoStuffInStandardUserContext()
{
    //do code that does
    //not require elevation
    //
    //

    //then run this method with Elevated Privileges
    SPSecurity.RunWithElevatedPrivileges(ExecuteDataAccess);

    //do other non elevated tasks...
}

private void ExecuteDataAccess()
{
    using(MyDBDataContext context = new MyDBDataContext())
    {
        context.DoDataAccessStuff()....
    }
}
Gavin Osborn
A: 

One of my favorites despite the ugly implementation is the SPWeb.ProcessBatchData method that lets you process multiple operations in batch. It also lets you do stuff otherwise not possible via the object model. For example creating a new uncustomized Web Part page.

Lars Fastrup
A: 

THE DOCUMENTATION SUCKS SO MUCH THAT I'D CONSIDER THE ENTIRE API A HIDDEN FEATURE!!!!

Pierreten