Dec
23

Choosing a storage medium for configuration items in SharePoint 2010

After passing Microsoft’s exam 70-576 – PRO: Designing and Developing Microsoft SharePoint 2010 Application,  I’ve had a real desire to utilize the knowledge learned across my day to day work.  One of the common questions I used to keep asking myself was “Where is the best place to store my configuration values?”

Of course, after being through the exam material over and over again, the answer is simple.  “It Depends!”

One of the exam objectives in the Managing Application Development section is around defining an application configuration approach. (http://www.microsoft.com/learning/en/us/exam.aspx?id=70-576#tab2)  “This objective may include … defining “web.config” modifications, Lists as a configuration option, Property Bags, declarative vs. programmatic, SP persisted objects.

So you are probably reading this with the following burning question:

Where is the best place to store the URL for a master list? or
Where should i store a SQL connection string? or even (but hopefully not)
Where can I store this password?

There’s no one size fits all approach with this, so what I have done is listed some of the more common options, and some (hopefully) helpful information about each.

  • web.config File
    The web.config file is a popular choice for configuration items, particularly for .NET developers who are starting to ply their trade in SharePoint.  Its important to note that SharePoint stores a web.config file for each Web Application (in the [DRIVE]:\inetpub\wss\VirtualDirectories\[WebApplication]\ folder by default).  Making a change to the web.config file also (automatically) recycles the associated web application, causing an outage to every site collection hosted on that web application.
    Because the web.config file is a physical file on the SharePoint server itself, only an Administrator would be able to make modifications that are required.  This is also very relevant when the web application is hosted on multiple servers in a load balanced (or similar) scenario, changes made to one web.config file will only affect processes on that particular server node.
    I’ve had some tough times in the past trying to debug issues related to incorrectly formatted web.config files causing an entire web application to be unavailable.  Perhaps it could be a reflection of my ability to work with XML documents, but it’s certainly not an option if end-users need to be able to make updates.
  • Property Bags
    When coding with the SharePoint 2010 object model, you’ll find the “Properties” property bag on many classes such as SPSite, SPWeb and more. The property bag is simply a StringDictionary that’s persisted on those objects.  What’s important to note is that the property bag doesn’t have any granular security available, but you can manage this by being selective about the scope you choose.  You’ll also need to make you keys unique to avoid conflicts with other applications using the same property bag.
    You can also go ahead and make a UI for interacting with the Property Bag if you have requirements around users updating the configuration items.  I haven’t used it myself, but you may find this codeplex project is a good start:  http://pbs.codeplex.com/
  • SharePoint Persisted Objects
    The SPPersistedObject goes one step further than the Properties Bag and allows you to store objects against the SPFarm object, rather than just strings.  You can get a persisted object by using the GetObject method on an SPFarm object, or the GetChild method of the SPPersistedObject class  The following MSDN article might be of useful reference: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.sppersistedobject.aspx
  • SharePoint Lists
    The most user-friendly option, and that is important if your end-users need to able to make updates.  You’ve got an option here that won’t need a lot of additional development (if any).  If you have a set of business rules around the allowable configuration values, you’ve also got a lot of Out Of the Box friendliness right at your fingertips (think field types, list validation, security, etc.).

Hopefully after reading this, you can now make an informed design decision on configuration item storage.

Permanent link to this article: http://www.scolts.com/?p=65

Dec
14

70-576

I was fortunate enough to find some time in the last few weeks to prepare for Microsoft’s PRO Developer Exam for SP2010. Thanks to Matt Menezes who searched high and low through the web to dig up some great study material.  (See his article: http://spmatt.wordpress.com/2011/12/08/how-i-passed-70-576/)

I’m very happy to announce that I passed the exam on my first go early this week!

Permanent link to this article: http://www.scolts.com/?p=62

Feb
18

Reverting C2WTS to run as Local System

I’ve done a lot of work recently debugging Kerberos issues with SharePoint 2010.  If you find yourself in the same boat, do yourself a favour and read The SharePoint 2010 Kerberos Guide.

One thing I’ve had to do on several occasions, is change the account that the Claims to Windows Token Service runs as from a domain account back to the Local System account.  You may have noticed that once you’ve used Central Admin to change this from Local System to your service account, there’s no means to change this back.

 There seems to be little information out there on how to do this.  Luckily, I finally came across an update from Andras Gaas that explains how to do it on a single server environment.  If you have multiple servers in your farm, you may have more than one instance of the C2WTS running – in which case, you will need to modify the PowerShell command slightly:

 $claims = Get-SPServiceInstance | where {$_.TypeName -eq “Claims to Windows Token Service”}
$claims[0].Service.ProcessIdentity.CurrentIdentityType = 0
$claims[0].Service.ProcessIdentity.Update()
$claims[1].Service.ProcessIdentity.CurrentIdentityType = 0
$claims[1].Service.ProcessIdentity.Update()
$claims[2].Service.ProcessIdentity.CurrentIdentityType = 0
$claims[2].Service.ProcessIdentity.Update()

Don’t forget: you will need to restart the Claims To Windows Token Service (in Central Admin > Services on Server or otherwise) on each server.

Permanent link to this article: http://www.scolts.com/?p=56

Jul
13

Upgrading SharePoint

I’m in the middle of an upgrade process of a large MOSS 2007 server farm to SharePoint 2010.  Rather than performing an in-place upgrade, we are opting to migrate the existing site collections to a newly installed SharePoint 2010 farm.

The major positive from this process is the ability to perform dummy runs without affecting the production farm.  Depending on the size and complexity of the environment, this may be worth the hassle of replicating all of the customisations and configurations.

At a very high level, the process involves an initial migration and configuration, then iterating through test runs a number of time, then performing a final migration to production:

Setup Process

  • Install SharePoint 2010
  • Provision and configure of Service Applications
  • Make a copy of the MOSS 2007 content database
  • Create a SharePoint 2010 Web Application
  • Connect the copied content database to the new site collection. (This updates the content database to be SharePoint 2010 compatible.)
  • Install missing solutions and customisations.

Testing Process

  • Make a copy of the MOSS 2007 content database
  • Connect the copied content database to the new site collection.
  • Continue to install any missing solutions and customisations.
  • Testing and Comparison

Production Migration

  • Cross your fingers.  (I mean it!)
  • Make the MOSS 2007 content database read only.
  • Make a copy of the MOSS 2007 content database.
  • Connect the copied content database to the new site collection.
  • Make any required DNS changes

Its important to be very thorough when checking your SharePoint 2010 site for differences and errors.  I was unfortunate enough to come across several customisations that were not packaged up into a SharePoint solution.

I have also seen some strange behaviour in these migrations such as Web Parts losing their title and even once lost one (yes, only one) web part page.

Permanent link to this article: http://www.scolts.com/?p=54

Apr
28

SharePoint Session State Troubleshooting

I am finding myself using session variables in custom web parts, but need to perform a few tweaks in most SharePoint environments to get them running.

If your SharePoint page is throwing an error because of a control like this, read on:

If the page throws the following error when trying to access Context.Session["xyz"]

Object reference not set to an instance of an object.

Or, you can’t enable session state in Central admin > Application Management > Configure Session State, with the following warning appearing:

Some applications will not function correctly without session state enabled. A Shared Service Provider must be created to enable session state.

Warning: Some applications will not function correctly without session state enabled.

The first step here is to create a Shared Service Provider. I won’t go into the details here, but this should take about five minutes without scripts in a development environment.

You will probably see one of the following errors:

An unexpected error has occurred.

(Set customerrors=”off” in the appropriate web.config file.)

Then:

Unable to serialize the session state. In ‘StateServer’ and ‘SQLServer’ mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in ‘Custom’ mode.

Again, in the same web.config file, look for the following string

<sessionState mode=”SQLServer” sqlConnectionString=”ConnString” />

And replace it with

<sessionState mode=”InProc” />

Happy Developing :)

Permanent link to this article: http://www.scolts.com/?p=36

Apr
15

Hiding Page Elements

These days I seem to find myself stripping away the chrome from document libraries more often than I expect to.  “Why?” I hear you ask, “Why wreck the SharePoint presentation layer?”.  Occasionally, users want to embed a document library in an Iframe of another application; the Iframe might too small to render the SharePoint page in its entirety; or the stakeholder may not want end users to navigate too far away.  I’m sure that there are some other reasons; some probably more valid than others.

It’s quite easy to add a Content Editor Web Part to the page containing the default view of a library to hide the chrome, or create a page with the web part as well as a list web part to render the library:

  • Edit the page containing the list view and add a Content Editor Web Part.
  • Add the following text into the Source Editor:

    <style>
    .ms-leftareacell,.ms-globallinks,.ms-siteaction,.ms-areaseparatorleft,.ms-rightareacell,.ms-areaseparatorright, .ms-areaseparatorcorner,.ms-titlearealeft,.ms-titlearearight,.ms-searchform,.ms-banner,.ms-buttonheightwidth, .ms-buttonheightwidth2,.ms-globaltitlearea
    {
    display:none;
    }
    </style>

  • Save and Exit

If you decide you want to change what you’ve done, one thing you’ll notice is that we have hidden the Site Actions menu, stopping us from editing the page again.   You can use a query string to get back into edit mode (see my last post).

Another handy thing to do here is to modify the navigation so that links from SharePoint to this library don’t go to the default view without the navigation controls.

Permanent link to this article: http://www.scolts.com/?p=30

Jun
11

SharePoint Query Strings

When working on a SharePoint site, there are times when you need to be familar with the query strings that are used. Many SharePoint developers will know what I mean – Edit Page, Web Part Maintenance Page, List Filters.

Here’s a small list that I have initially taken from the author at Abstract Spaces. I’ll add to this list as I think of them.

Add Web Parts/Browse ToolPaneView=2
Add Web Parts/Search ToolPaneView=3
Edit Mode mode=edit
View Mode mode=view
Shared Mode PageView=Shared
Personal Mode PageView=Personal
Web Part Maintenance contents=1

Permanent link to this article: http://www.scolts.com/?p=22

May
18

Recover (Exploit) a SharePoint Application Pool Password

I came across this article by Kirk Liemohn at Threewill that shows how you can recover the application pool password for a SharePoint site using PowerShell.

Given that the application pool account is quite often used the system account, if you are an SharePoint Administration this could be a major cause for concern when you have 3rd party consultants.

I was – purely for argument sake – able to do the same thing in a web part with 4 lines of code:

SPSite site = SPContext.Current.Site;
SPWebApplication webApp = site.WebApplication;
SPApplicationPool AppPool = webApp.ApplicationPool;
this.Controls.Add(new LiteralControl(AppPool.Username + " : " + AppPool.Password));

Permanent link to this article: http://www.scolts.com/?p=19

Mar
23

Jaap Vossers

I came accross some of the work of Jaap Vossers today. Jaap is a Dutch SharePoint developer/architect currently plying his trade in England. Indeed his work is top quality and somewhat unique.

Without stealing his thunder, I particularly like the Inline Site Settings and Instant List Filter projects simply because of their usefullness.

The Inline Site Settings project provides developers with the perfect shortcut to the Site Settings page for developers, while the Instant List Filter provides end users with list filters that are simple to use and uses JQuery to avoid page refreshing!

You can find Jaap’s blog at blog.vossers.com and his projects at www.codeplex.com/site/users/view/jvossers

Permanent link to this article: http://www.scolts.com/?p=14

Feb
21

Failed to activate feature

I was surprised when a feature from a solution I had developed failed to activate in a new site collection, despite being unaltered from what was working on another site collection moments earlier.

The error SharePoint (WSS v3 in this case) threw at me was:

“Failed to activate feature ‘<Feature Name>’ (ID:<Feature ID>)”

Not a very helpful error message; however this was resolved simply by resetting IIS. Luckily this was only a development environment.

Permanent link to this article: http://www.scolts.com/?p=10

Older posts «