Delete All Items Ribbon Button


February 8, 2012 - 17:38, by Steven Van de Craen - 1 Comments

A SharePoint 2010 Sandboxed Solution that adds a Ribbon Button that recycles all items in a Document Library with a single mouse click.

I' have created this miniproject more as an academic exercise in creating a Ribbon Button than for real business value. It can come in handy for development environments sometimes.

Ribbon

Installation and activation

Download from here (Ventigrate Codeplex Repository)

Upload the WSP (sandbox solution) to the Site Collection Solution Gallery and activate it

Solution Gallery

Activate the Site Collection Feature

Site Collection Features

Final note

Some lessons learned and things worth noting:

  • Use a Module to deploy resource files to a folder or library like the Style Library (Sandbox cannot access the Layouts folder)
  • The Module will overwrite the existing resource files with a newer version, but will not delete them
  • Working with ECMAScript seems to have no effect on resource or resource quota
  • Use InPrivate Browsing for testing Ribbon development, this avoids caching of Ribbon resources
  • CustomAction.ScriptSrc points to the Layouts folder when using relative URLs. Use ~SiteCollection if you want to reference a resource in the Site Collection


The sandbox is too busy to handle the request


December 7, 2011 - 16:32, by Steven Van de Craen - 2 Comments

SharePoint 2010 and SharePoint Online (Office 365) allow for custom development in the form of Sandbox Solutions. Your code is restricted to a subset of the SharePoint API but allows you do most regular operations inside a Site Collection.

Problem

Here’s a scenario that fails every time and everywhere:

  • Create a sandboxed Event Receiver that is registered to ItemUpdating
  • Create a sandboxed Web Part that does an SPListItem.Update() from the SharePoint Object Model
  • Watch how the sandbox errors out with the following message

[SPUserCodeSolutionExecutionFailedException: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: The sandboxed code execution request was refused because the Sandboxed Code Host Service was too busy to handle the request.]

  • Now just edit the item from the SharePoint UI and watch how that works wonderfully well

Sandbox Request Architecture

So what’s going on here ?

Sandbox request architecture

In light of this you might conclude that there’s no possible communication between two sandbox code requests (the Web Part and the Event Receiver). As good an explanation as any, so feel free to chime in.

Other things

Here are some other things I stumbled upon while researching this issue:

  • ItemUpdated is not affected and works fine
  • You cannot make your “after” events Synchronous in a Sandbox as they won’t fire
  • (Sandbox) Event Receivers can only be registered declaratively in the Feature XML
  • The certificate checking issue (crl.microsoft.com) has the same error message, but is unrelated to this issue
  • Triggering the update from non-Sandbox code works fine

Workaround

So how about we conclude with a workaround ?

In some cases you could use the “after” Event Receiver rather than the “before” Event Receiver, but isn’t really a sound solution.

The best option would be to rewrite the Web Part to run its code on the client, either through Client OM (ECMAScript or Silverlight), or the SharePoint Web Services.

Client Application Models in SharePoint 2010

http://msdn.microsoft.com/en-us/library/ff798452.aspx


SharePoint: SPWeb.Properties versus SPWeb.AllProperties


March 6, 2011 - 07:41, by Steven Van de Craen - 4 Comments

Property Bag

SPWeb exposes two ways of interacting with the property bag:

  • SPWeb.Properties exposes a Microsoft.SharePoint.Utilities.SPPropertyBag
  • SPWeb.AllProperties exposes a System.Collections.Hashtable

The former is considered legacy, also it stores the Key value as lowercase, while the latter keeps the casing of Key and Value intact.

Here’s a code sample:

1 string url = "http://intranet"; 2 3 using (SPSite site = new SPSite(url)) 4 { 5 SPWeb w = site.OpenWeb(); 6 w.AllProperties.Add("First Key", "First Value"); 7 w.Update(); 8 9 SPPropertyBag p = w.Properties; 10 p.Add("Second Key", "Second Value"); 11 p.Update(); 12 }

You can see the properties for a web using SharePoint Designer:

SharePoint 2007:

2007 Web Property Bag

SharePoint 2010:

2010 Web Property Bag

Case matters

When you configure a Search Center in the Site Collection Settings, a property named “SRCH_ENH_FTR_URL” stores the location to the Search Center. If this property isn’t entirely uppercase, it won’t be picked up correctly.

Sandbox Solutions

So what about Sandbox Solutions in SharePoint 2010 ?

- SPWeb.AllProperties can only be read from. Updating it doesn’t throw any exceptions but has no effects either.

- SPWeb.Properties cannot be used and throws a TypeLoadException:

Error in Sandbox for SPPropertyBag


BIWUG | SPSaturday: wrap up


May 12, 2010 - 08:49, by Steven Van de Craen - 0 Comments

Last Saturday (8 May 2010) the first SharePoint Saturday event in Belgium took place. It was a day full of SharePoint 2010 aimed specifically at developers. As promised here’s the slide deck and demo files I used.

 BIWUG SPSaturday

 

/Steven