Archive for December 27, 2012

Merry Christmas

Happy Christmas and a prosperous New Year, I hope 2013 is everything you expect and more!

Get Default Database Infomation

SharePoint Short #15

Looking for a quick an easy way of retrieving the default content database information, like the SQL instance (i.e. servername\instance)?

string sqlServerInstance = SPWebService.ContentService.DefaultDatabaseInstance.NormalizedDataSource;

or individually

string sqlInstance = SPWebService.ContentService.DefaultDatabaseInstance.Instance;
string sqlServer = SPWebService.ContentService.DefaultDatabaseInstance.Server;

The SPWebService class provides an easy and quick way of retrieving this, along with the administration database specific properties.

Impersonating Current App Pool User

Using SharePoint it’s easy to run a block of code with elevated permissions:

    using (SPSite elevatedSite = new SPSite(siteId))
        using (SPWeb elevatedWeb = elevatedSite.OpenWeb(wedId))
            // operations using elevated SPWeb object...

This is fine for SharePoint related impersonations. Any code executed within the elevated block that authenticates using an object instantiated outside the RunWithElevatedPrivileges block will run using the context of the current user and not the elevated account. So for example, if you wanted to make a web method call using a single user (or connect to a database) and not the current context, the following code block will achieve this for you:
Read more

Enhanced Lookup Field – Part 4

This is the fourth and final part of the post describing how to create a custom lookup field for SharePoint.

Other pages in this post are:

This post describes how to implement the hidden related field for controlling the display within views.

Read more


Get every new post delivered to your Inbox

Join other followers: