Archive for the ‘SharePoint 2010’ Category

InfoPath error after installing SharePoint 2010 Service Pack 2

Tuesday, October 8th, 2013

Interesting discovery yesterday that I thought I should share. After installing SharePoint 2010 Service pack 2 a customer ran into problems with their InfoPath forms. The generic error message was “The custom code in the form cannot be run. This functionality may be deactivated on the server”. Looking in the ULS log there were some more information:

Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Could not load type 'Microsoft.SharePoint.Administration.SPService' from assembly 'Microsoft.SharePoint, Version=14.900.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.    Server stack trace:     
 at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.QueryDataOnLoad(DataAdapter documentDataAdapter, DataObject documentDataObject)    
 at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.ExecuteInitOnLoadForDataObjects()    
 at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.LoadFromRemoteContext(Boolean firstOpened, String editingSessionId, Solution solution, Byte[] serializedState, Byte[] serializedVersionState, Dictionary`2 inputParams, OpenParameters openParameters)

After a lot of trial and errors I did some reflection on the Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.QueryDataOnLoad method in Microsoft.Office.InfoPath.Server.dll. The method had a small code change between the Cumulative Update the customer was on and Service Pack 2.

Before Service Pack 2

Before Service Pack 2

After Service Pack 2

After Service Pack 2

The small code change, FormsService formsService = FormsService.TryGetLocal(), uses Microsoft.SharePoint.Administration.SPService. The problem occurs when this code is run from within the sandbox process. Then SPService is not available just like the error message said. QueryDataOnLoad gets called if you have an InfoPath form with data connections that loads on startup.

It is really easy to reproduce this bug. Just install SP2, create an InfoPath form with a data connection (that loads a SharePoint list at startup) and also add code-behind for the loading event. Fortunately the line of code causing the problem is removed in August 2013 Cumulative Update.

Error when saving reusable workflow as template

Thursday, October 11th, 2012

If you get an error message saying “The server was unable to create your template. Please notify your server administrator” when you try to save a reusable workflow as template, the reason could be that the name is too long.

SharePoint Designer Error

When I ran into this I looked in the ULS log and found this: 

 SPSolutionExporter: System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

After renaming the workflow to a shorter name it worked (in my case only 10 characters worked). Looking at the ULS some more I found out that the original name I chose was still used in combination with the new name. So if you still want that long name for your workflow you could first create the workflow with a short name, publish it and then rename it to the long name. Now you can hopefully save it as a template.

Don’t use Linq on collections in DocumentSetTemplate

Thursday, October 11th, 2012

If you ever find yourself working with document sets through the SharePoint API, don’t use Linq on the Collections in DocumentSetTemplate. Even though they implement IEnumerable<T> they have not wired everything up internally so you will get NullReferenceException (Object reference not set to an instance of an object) when using any Linq statement on them. This applies to AllowedContentTypes, DefaultDocuments, SharedFields and WelcomePageFields.

You can easily reproduce this by running this code:

var ct = web.ContentTypes["Document Set"];
var template = DocumentSetTemplate.GetDocumentSetTemplate(ct);

Hopefully this will be fixed some day in the API

Debugging ItemAdded when InfoPath has codebehind in sandbox

Wednesday, October 3rd, 2012

 I was working with a customer that had an InfoPath form with code behind running as a sandboxed solution. The forms library also had an event receiver with both ItemAdded and ItemUpdated. We could debug ItemUpdated but not ItemAdded. I finally found that if the form has code behind running as a sandboxed solution you have to attach to the SPUCWorkerProcessProxy.exe process to debug ItemAdded. Even using Attach to All SharePoint Processes in CKSDev won’t do it since the SPUCWorkerProcessProxy.exe process is not attached. ItemUpdated will run in the normal SharePoint process and not in SPUCWorkerProcessProxy.exe.

jQuery Site Assets

Friday, February 3rd, 2012

There is a conflict in the SharePoint API and jQuery that causes the JavaScripts in Site Assets libraries to stop functioning. This is because the APIs both use $. To avoid this conflict you can override the $-function and instead use the jQuery-function.

More information on how you override can be found here:

Week numbers in calendar view – revisited for SharePoint 2010

Saturday, April 9th, 2011

A while ago I wrote a post on how to add week numbers to the monthly calendar view. The customer I built this for is now upgrading to SharePoint 2010 and since the calendar is now completely rebuild with ajax functionality I had to revisit and rewrite this code. This time I’m doing it with jQuery instead which in my opinion leads to a much cleaner solution. Thanks to Mike Smith’s post for showing how to intercept the asynchronous ajax events  of the calendar. The neet thing about this is that even if asynchronous events happen like if you page to a new month, the calendar still gets updated with new week numbers. For calculating week number I’m using the same javascript as in my post on how to add week numbers to the gantt view.

Week Numbers in Calendar

This is the code you need to put in a content editor web part on the same page as the calendar is displayed.

<script src="" type="text/javascript"></script>
<script type="text/javascript">

Date.prototype.getWeek = function () {
   //lets calc weeknumber the cruel and hard way 😀
   //Find JulianDay
   var year = this.getFullYear();
   var month = this.getMonth();
   var day = this.getDate();

   month += 1; //use 1-12
   var a = Math.floor((14 - (month)) / 12);
   var y = year + 4800 - a;
   var m = (month) + (12 * a) - 3;
   var jd = day + Math.floor(((153 * m) + 2) / 5) +
                (365 * y) + Math.floor(y / 4) - Math.floor(y / 100) +
                Math.floor(y / 400) - 32045;      // (gregorian calendar)

   //now calc weeknumber according to JD
   var d4 = (jd + 31741 - (jd % 7)) % 146097 % 36524 % 1461;
   var L = Math.floor(d4 / 1460);
   var d1 = ((d4 - L) % 365) + L;
   NumberOfWeek = Math.floor(d1 / 7) + 1;
   return NumberOfWeek;

function updateCampaignCalendar() {

   // calendar rows
   jQuery('TH[evtid="week"]').each(function () {

      // add week numbers
      var firstDay = new Date(jQuery(this).attr('date'));
      if (firstDay.toString() != "NaN" && firstDay.toString() != "Invalid Date") {
         var week = firstDay.getWeek(firstDay.getDay());
         jQuery(this).children("DIV").attr("innerHTML", week);


// hook into the existing SharePoint calendar load function
function calendarEventLinkIntercept() {
   var OldCalendarNotify4a = SP.UI.ApplicationPages.CalendarNotify.$4a;
   SP.UI.ApplicationPages.CalendarNotify.$4a = function () {

Solution to: Missing server side dependencies 8d6034c4-a416-e535-281a-6b714894e1aa

Monday, November 1st, 2010
The new Health Analyzer in SharePoint 2010 is great and you should always try to clean up all errors in this list. One error I had after installing the RTM version of SharePoint Server was:
[MissingWebPart] WebPart class [8d6034c4-a416-e535-281a-6b714894e1aa] is referenced [X] times in the database […AdminContent…].
There are many suggested solutions to this problem on the internet (Accessing search administration, Querying the databasesetup SharePoint Foundation Help Search and crawl help files)
What worked for me was accessing these search pages in the help-site-collection in Central Administration. (just ignore the error about missing list).
After that just reanalyze the issue in the Health Analyzer and hopefully it will dissapear.

SharePoint 2010 Foundation vs. Server

Wednesday, May 12th, 2010

Interested in what features are included in SharePoint 2010 Foundation and what’s not included. This is a really good summary: