The sandbox is too busy to handle the request
December 7, 2011 - 16:32, by Steven Van de Craen
Categories: Event Receivers, Sandbox Solutions, SharePoint 2010
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 ?

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.

http://msdn.microsoft.com/en-us/library/ff798452.aspx
1 Comments
October 19, 2011 - 12:01, by Steven Van de Craen
Categories: SharePoint 2007, SharePoint 2010, Content Types
Ever enabled Content Types on a library, removed the default “Document” Content Type and then added your own document Content Type ? If you do it in that order it will set “Folder” as the Content Type for uploaded files.
There’s no apparent way in the user interface to change the default Content Type, since “Folder” is not visible in the list:

If you don’t have a lot of lists already or you can only access SharePoint through the browser, the quickest way to fix this is to add the default “Document” Content Type to the list and immediately remove it again.
If (like in my case) you already have a lot of lists, you can script the Content Type Ordering:
using (SPSite site = new SPSite(url)) { foreach (SPWeb web in site.AllWebs) { foreach (SPList list in web.GetListsOfType(SPBaseType.DocumentLibrary)) { if (list.ContentTypes["Main Document"] != null) { SPFolder folder = list.RootFolder; List<SPContentType> lstCT = new List<SPContentType>(); lstCT.Add(list.ContentTypes["Main Document"]); folder.UniqueContentTypeOrder = lstCT; folder.Update(); } } web.Close(); } }
The above code loops all libraries on all sites in a Site Collection and sets my “Main Document” Content Type as the only (and default) Content Type. If you have different needs feel free to adapt as required.
October 17, 2011 - 21:57, by Steven Van de Craen
Categories: SharePoint 2010
New APIs in SharePoint 2010 Service Pack 1 (SP1)
Funny enough a colleague pointed out to me he couldn’t find the UserProfile.ModifyProfilePicture method. Neither could I (running Service Pack 1 + June 11 CU).


Can you ? Perhaps it was removed in the June 2011 Cumulative Update ?
UPDATE (18 Oct 2011):
Had a chat with Koen Vosters on on the matter, and he verified the absence of this method in a SP1 build VM. So what happed with that method ? Was it scheduled and removed in the very end? Anyway thanks Koen for verifying !!
October 13, 2011 - 12:04, by Steven Van de Craen
Categories: General, SharePoint 2007, SharePoint 2010
If you happen to change the Windows Time Zone settings AFTER Central Administration has been provisioned, you will see that the time zone/date format is not updated in the administration pages:

Luckily, the fix is quite easy. You can just update the Regional Settings of the Central Administration site. Since this option is hidden from the Site Settings, you’ll have to navigate to it manually:
http://[centraladministration/_layouts/regionalsetng.aspx

Here’s a sample of setting it to Brussels time zone and Dutch Locale:

As you can see only the Time Zone is taken into account while format is still using US Locale. This only applies for certain Administration Pages such as Search Administration. The “Timer Job Status” page for example shows the specified (Dutch) format:

October 2, 2011 - 12:42, by Steven Van de Craen
Categories: BIWUG, General
BIWUG is announcing another session about SharePoint on Thursday October 27th 2011 in the Microsoft Belgium offices.
Agenda
18:00-19:00 Welcome with snacks
19:00-19:15 Introduction
19:15-20:15 SharePoint Governance (Speaker Patrick Sledz): Stop thinking about features features features when talking about governance.
When designing governance for a SharePoint implementation, a lot (not to say all) energy and words go out to technical stuff, SLA's and not to the things that define the business value. And the business value is not only a perfect technically tuned and performant SharePoint farm (if that even exists).
20:15-20:30 Break
20:30-21:00 The past, present and the future of BIWUG
During a seemingly quiet period, a lot has been going on behind the scenes. The result of all this secrecy will be revealed in the second part of the evening.
21:00-21:30 SharePint!
Of course there is also an opportunity to network, socialize and discuss the matter explained the previous hours... therefore SharePint!
Location: Microsoft Belgium Corporate Village - Bayreuth Building, Leonardo Da Vincilaan 3, 1935 Zaventem
Registration is now opened on the BIWUG site www.biwug.be
See you there !
September 30, 2011 - 16:31, by Steven Van de Craen
Categories: Claims, SharePoint 2010
This project is further maintained at the Ventigrate Codeplex Repository (http://ventigrate.codeplex.com).
Please go there to get the latest news or for any questions regarding this topic.
Page was cross-posted to this blog on 09/30/2011.
External User Management
The External User Management solution allows for easy management of users and groups for a SharePoint 2010 environment configured for Forms Based Authentication (FBA), handled by Claims Based Authentication (CBA). It contains management pages for Site Collection Administrators to:
User Management tasks
- Add users
- Edit a user (edit details, password or role membership)
- Unlock a user
- Delete a user

Role Management tasks


Prerequisites
Log4Net is a highly flexible and configurable logging mechanism and is used by this solution. It is included in the Deployment Package and can be installed as a SharePoint Solution Package (.wsp) using STSADM or PowerShell:
STSADM -o addsolution -filename Log4Net.v1.2.10.wsp
STSADM -o deploysolution -name Log4Net.v1.2.10.wsp -allowgacdeployment -immediate
Installation
Add and deploy the SharePoint Solution Package (.wsp) using STSADM or PowerShell:
STSADM -o addsolution -filename Ventigrate.Shared.ExternalMembership.wsp
STSADM -o deploysolution -name Ventigrate.Shared.ExternalMembership.wsp -allowgacdeployment -immediate
Add an internal Alternate Access Mapping "http://extranet" for the Zone on the WebApplication that has the Membership and Role Provider (Claims) configured in it's web.config. This is the key to getting the administration pages to connect to the correct provider.

Activate the Site Collection Feature to make a link to the management pages appear in Site Collection Administration.

FAQ
Q. Will this solution work on SharePoint 2007 ?
A. No, there are certain features that make it work only in SharePoint 2010. But there are similar projects for doing FBA User Management in SharePoint 2007 on CodePlex (CKS http://cks.codeplex.com/).
Q. I don't use a Role Provider or my Membership Provider doesn't allow certain tasks such as Password Change. Can I use this ?
A. It will probably throw some issues since this code wasn't really designed to capture any possible Membership or Role Provider configuration. Feel free to provide improvements through the Discussion Boards http://ventigrate.codeplex.com/discussions.
Q. Will the Advanced Computed Field still work if I migrate from SharePoint 2007 to SharePoint 2010 ?
A. Definitely, but you'll need to upgrade the SharePoint 2007 solution package to the SharePoint 2010 version. Either retract and delete the SharePoint 2007 package prior to deploying the SharePoint 2010 package, or do an upgrade to the new solution. Make sure to IISRESET afterwards !
Q. Other questions ?
A. No problem. Ask them in the Discussion Boards http://ventigrate.codeplex.com/discussions.
August 25, 2011 - 17:28, by Steven Van de Craen
Categories: InfoPath, SharePoint 2003, SharePoint 2007, SharePoint 2010
A short blog on how the Promoted Fields seem to behave for InfoPath forms stored in SharePoint.
They are created as fields (Date, Text, …) and have the XPath property configured to the field in InfoPath (example: /my:myFields/my:field1)
When the form is stored in the library, the value of the XPath’s InnerText is stored in the List Item. It is by no means a live evaluation of the XPath.
Through code one can update the XPath value of the SPField. This does not affect existing forms since the value is persisted during form save, only new forms are affected.
SPSite site = new SPSite(url); SPWeb web = site.OpenWeb(); SPList list = web.GetList(url); SPField field = list.Fields["Field1"]; field.XPath = "/my:myFields/my:field1"; field.Update();
When you set the XPath to an element that has child elements, the InnerText will render all the elements contents as you’d expect:
value 1
value 2
When the XPath is set to "/my:myFields”, the Promoted Field value will be “\n\t11\n\t22\n” (it preserves indents).
That’s all for this quick blog post !
June 28, 2011 - 09:10, by Steven Van de Craen
Categories: SharePoint 2010, Workflow, Debugging
In my previous post “SharePoint 2010: Programmatically Approving/Rejecting Workflow” I mentioned the possibility of an issue when programmatically altering a workflow task. I have been testing it on several SharePoint 2010 farms with different parameters (different patch level, etc).
UPDATED July 2, 2011: RESOLVED
Set up
A simple SharePoint Designer 2010 workflow with the “Start Approval Process” action published to a document library. You start the workflow and a task is created for the approver.
The Approver is set to another test user, but all my code and script runs as the administrator (and thus System Account). Makes no difference though.
Note: when running the workflow multiple times (for testing), make sure to delete all tasks that are linked to your item. Or adapt the code below to not just take the first task in the collection…
Issue experienced
You alter the workflow task using a Visual Studio Console Application or Windows Application with the following (or similar code):
1 string url = "http://intranet/Shared Documents/Instructions.txt"; 2 using (SPSite site = new SPSite(url)) 3 { 4 SPWeb web = site.RootWeb; 5 SPListItem item = web.GetFile(url).Item; 6 SPWorkflowTask task = item.Tasks[0]; 7 8 Hashtable ht = new Hashtable(); 9 ht["TaskStatus"] = "Approved"; 10 11 SPWorkflowTask.AlterTask(task, ht, false); 12 }
After the code has run successfully you don’t see anything happen in the workflow status page. On some occasions you get “Due to heavy load, the latest workflow operation has been queued. It will attempt to resume at a later time” which could mean that the timer job hasn’t completed successfully yet. This message may or may not disappear for you.
Also, when trying to do a second alteration to the workflow task (by code or in the UI) you get “This task is currently locked by a running workflow and cannot be edited”.
So somehow your action was registered but not executed…
PowerShell to the rescue
Terminate the workflow (because it really hangs and there’s not much you can do with it) and kick off a new one.
Now open the SharePoint 2010 Management Shell (PowerShell) and run the following (or similar code):
$s = Get-SPSite("http://intranet")
$w = $s.RootWeb
$i = $w.GetFile("http://intranet/Shared Documents/Instructions.txt").Item
$t = $i.Tasks[0]
$ht = new-object Hashtable
$ht["TaskStatus"] = "Approved"
[Microsoft.SharePoint.Workflow.SPWorkflowTask]::AlterTask($t, $ht, $false)
This WILL work and correctly finish the approval cycle in any of my tested environments.
Notes
You can really test this over and over and over; it will work in PowerShell but not in the Visual Studio 2010 application. I have tested Release versus Debug, in and out Visual Studio, etc.
Solution (July 2, 2011)
The big difference in both techniques is that the PowerShell remains open and isn’t disposing any objects. This allowed the workflow engine to complete the task.
Option #1
1 SPWorkflowTask.AlterTask(task, ht, true);
From MSDN:
“If true is passed as the argument to fSynchronous, this method waits up to 30 seconds to determine whether the attempted update was accepted by the workflow schedule as valid. The method then returns true if the update was accepted and not rolled back, or false if the update was not accepted. If false is passed as the argument to fSynchronous, this method always returns true.”
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowtask.altertask.aspx
I have found this working most of the times, however some test runs still experienced the issue. Perhaps my test environment isn’t powerful enough or the action takes just a little too long to kick in ?
Option #2
Using the code below I learned it took about 21 seconds for the task to complete:
1 int i = 1; 2 while (!(bool)item.Tasks[taskId]["Completed"]) 3 { 4 Console.Clear(); 5 Console.Write("" + i + " " + task["Completed"]); 6 Thread.Sleep(1000); 7 i++; 8 }
That should give ‘option #1’ suffice time to complete the task, but still it didn’t in all occasions. If you’re experiencing this you could write up your own delay either as replacement to, or in combination with ‘option #1’.
1 SPWorkflowTask.AlterTask(task, ht, true); 2 // Additional delay 3 while (!(bool)item.Tasks[taskId]["Completed"]) 4 { 5 Thread.Sleep(1000); 6 }
Related
Big kudos to my colleagues Tom De Wilde and Timmy Gilissen for helping me out !!
June 23, 2011 - 22:41, by Steven Van de Craen
Categories: SharePoint 2010, Workflow
Interacting with a workflow in SharePoint is relatively straight-forward if you understand the underlying process. I’ve done multiple projects in both SharePoint 2007 and SharePoint 2010 with some level of workflow interaction: starting a workflow, approving or rejecting a workflow task, or reassigning a workflow task.
Today however I reused that code on a SharePoint 2010 environment but the Task Approval didn’t kick in, rather the workflow seemed to ‘hang’ indefinitely.
SharePoint Designer “Start Approval Process” Workflow

Start the Approval process

(don’t mind the errors, they’re about a missing outgoing mail server)
Programmatically approve the task
1 bool result = false; 2 string url = "http://devsp/Shared Documents/Sample 1.docx"; 3 4 using (SPSite site = new SPSite(url)) 5 { 6 using (SPWeb web = site.OpenWeb()) 7 { 8 SPListItem item = web.GetFile(url).Item; 9 SPWorkflowTask wfTask = item.Tasks[item.Tasks.Count -1]; 10 11 Hashtable htProps = new Hashtable(); 12 htProps["TaskStatus"] = "Approved"; 13 14 result = SPWorkflowTask.AlterTask(wfTask, htProps, true); 15 } 16 } 17 18 MessageBox.Show("AlterTask Outcome: " + result);
Result

Some things to note
- If you have a localized site you need the translated equivalent of “Approved” and “Rejected”. For Dutch that would be “Goedgekeurd”
- Reassigning a task can be done by specifying a new SPUser value for the “AssignedTo” value similarly to the above Approve action
- Next post will be about some weird behaviour resulting in “This task is currently locked by a running workflow and cannot be edited” or “Note: Due to heavy load, the latest workflow operation has been queued. It will attempt to resume at a later time” messages
Follow up
May 26, 2011 - 16:07, by Steven Van de Craen
Categories: Advanced Computed Field, SharePoint 2010, Custom Field Types
Finally available: the SharePoint 2010 version of the Advanced Computed Field. Don’t know what it is ? Check this out:
http://ventigrate.codeplex.com/wikipage?title=Advanced%20Computed%20Field

(the Advanced Computed Field rendering a highlighted/italic item title)
<< Previous Next >>