March 2, 2012 - 08:28, by Steven Van de Craen
Categories: Advanced Computed Field, SharePoint 2010
Yesterday I updated the download and source code for the Advanced Computed Field at the Ventigrate Public Code Repository with an XSL stylesheet. This was needed to fix an issue with the field not rendering values when filtered through a Web Part Connection.
The Advanced Computed Field relies on CAML to have the most flexibility of formatting, since SharePoint 2010 introduces XSL based Fields I updated it with the CAMLRendering=”TRUE” flag. This seemed to work for everything except an issue reported by Federico Sanchez regarding Connected Web Parts.
Federico came with the solution to the problem by adding the XSL stylesheet (nothing else needed to be changed), so it really is a nice solution.
xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> <xsl:template match="FieldRef[@FieldType='AdvancedComputedField']" mode="Computed_body"> <xsl:param name="thisNode" select="."/> <xsl:value-of select="ddwrt:HtmlDecode($thisNode/@*[name()=current()/@Name])" disable-output-escaping="yes"/> xsl:template> xsl:stylesheet>
Solution upgrade
If you’re using the Advanced Computed Field in SharePoint 2010, it is advised to update the Solution Package (WSP) to the latest version (available in the download). It won’t break the existing use.
Download: link
March 1, 2012 - 16:31, by Steven Van de Craen
Categories: BIWUG, General, SharePoint 2010
Join SharePoint architects, developers, and other professionals on 28th April for the second Belgian ‘SharePoint Saturday’ event. SharePoint Saturday is an educational, informative & lively day filled with sessions from respected SharePoint professionals & MVPs, covering a wide variety of SharePoint-orientated topics. SharePoint Saturday is FREE, open to the public and is your local chance to immerse yourself in SharePoint!
SharePoint Saturday () is organised by BIWUG (), the Belux Information Worker User Group.
Extra details and registration information can be found here: http://bit.ly/spsbe2012.
See you there,
February 8, 2012 - 17:38, by Steven Van de Craen
Categories: SharePoint 2010, Sandbox Solutions, Ribbon, jQuery/JavaScript
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.
Installation and activation
Download from here (Ventigrate Codeplex Repository)
Upload the WSP (sandbox solution) to the Site Collection Solution Gallery and activate it
Activate the Site Collection Feature
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
February 2, 2012 - 11:59, by Steven Van de Craen
Categories: SharePoint 2010, Taxonomy, Event Receivers, .NET
Issue
Today I was troubleshooting a customer farm where Managed Metadata would remain empty in SharePoint, even though it was filled in correctly in the document’s Document Information Panel.
Digging through the internal XML structures of the DOCX and also the Content Type Schema and Field XML, I couldn’t find a reasonable explanation.
The library was configured with multiple Content Types, but the issue occurred only on some of them. It appeared that for those Content Types, the Managed Metadata field was Optional, not Required.
I tried reproducing that configuration in a new document library but there everything kept working, so the issue had to be with the existing library.
Further analysis, comparison and reflection showed that the problematic library was missing some Taxonomy-related Event Receivers.
There appear to be four (4) Taxonomy Event Receivers:
-
TaxonomyItemSynchronousAddedEventReceiver (ItemAdding) and TaxonomyItemUpdatingEventReceiver (ItemUpdating) are added when a Managed Metadata field is added to the List
-
TaxonomyItemAddedAsyncEventReceiver (ItemAdded) and TaxonomyItemUpdatedEventReceiver (ItemUpdated) are added when “Metadata Publishing” is enabled in the List Settings
The problematic library at the customer was lacking the first set of Event Receivers, which are responsible for syncing the hidden field.
Fix
I’ve written a one-off script (Console App) that loops all lists with a Managed Metadata field on all sites in the site collection and ensures the Taxonomy event receivers. That code was taken directly from TaxonomyField.AddEventReceiverIfNotExists.
using System; using System.IO; using System.Text; using System.Windows.Forms; using Microsoft.SharePoint; using Microsoft.SharePoint.Taxonomy; class Taxonomy_Fix { public static StringBuilder sb = new StringBuilder(); public static string nl = "\r\n"; public static string url = "http://intranet"; public static void FIXALL() { using (SPSite site = new SPSite(url)) { foreach (SPWeb web in site.AllWebs) { FixTaxonomyReceiverOnWebLists(web); web.Close(); } } File.AppendAllText(String.Format("c:\\{0:HH_mm_ss}.txt", DateTime.Now), sb.ToString()); MessageBox.Show(sb.ToString()); } private static void FixTaxonomyReceiverOnWebLists(SPWeb web) { for (int i = 0; i < web.Lists.Count; i++) { SPList list = web.Lists[i]; if (HasTaxonomyField(list)) { sb.AppendFormat("{0}{1} has Taxonomy Field{2}", url, list.RootFolder.ServerRelativeUrl, nl); EnsureTaxonomyHandlers(list); } } } private static bool HasTaxonomyField(SPList list) { bool result = false; foreach (SPField field in list.Fields) { if (field is TaxonomyField) { result = true; break; } } return result; } private static void EnsureTaxonomyHandlers(SPList list) { AddEventReceiverIfNotExists(list.EventReceivers, SPEventReceiverType.ItemAdding, typeof(TaxonomyField).Assembly.FullName, "Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver", "TaxonomyItemSynchronousAddedEventReceiver", SPEventReceiverSynchronization.Synchronous); AddEventReceiverIfNotExists(list.EventReceivers, SPEventReceiverType.ItemUpdating, typeof(TaxonomyField).Assembly.FullName, "Microsoft.SharePoint.Taxonomy.TaxonomyItemEventReceiver", "TaxonomyItemUpdatingEventReceiver", SPEventReceiverSynchronization.Synchronous); } private static void AddEventReceiverIfNotExists(SPEventReceiverDefinitionCollection eventReceiverCollection, SPEventReceiverType type, string assembly, string className, string receiverName, SPEventReceiverSynchronization sync) { if (eventReceiverCollection == null) { throw new ArgumentNullException("eventReceiverCollection"); } if (string.IsNullOrEmpty(assembly)) { throw new ArgumentNullException("Valid assembly name required"); } foreach (SPEventReceiverDefinition erd in eventReceiverCollection) { if (erd.Assembly == assembly && className == erd.Class && type == erd.Type && erd.Synchronization == sync) { sb.AppendFormat("\t>> no action required{0}", nl); return; } } SPEventReceiverDefinition erd2 = eventReceiverCollection.Add(); erd2.Name = receiverName; erd2.Type = type; erd2.Assembly = assembly; erd2.Class = className; erd2.Synchronization = sync; erd2.Update(); sb.AppendFormat("\t>> Added TaxonomyEvent Receiver{0}", nl); } }
Disclaimer: not responsible for this code. Run at own risk. Feel free to adapt or improve as desired or required.
Conclusion
I can’t really explain why only some Content Types were affected. I’m guessing the Optional/Required setting of the Managed Metadata field is involved somehow, but I didn’t really confirm that through testing.
Also not sure why the Event Receivers were missing in the first place. It could be because some “questionable” actions happened during the setup of the site, but it could as well be a bug in SharePoint 2010 RTM or later.
January 26, 2012 - 13:09, by Steven Van de Craen
Categories: SOAP, SharePoint 2010
Today we were experimenting with SharePoint 2010 CSOM (Client Side Object Model) and we noticed strange errors such as HTTP ERROR 417 were returned. When browsing to Lists.asmx and Sites.asmx we got the following error:
The top XML element 'string' from namespace 'http://schemas.microsoft.com/sharepoint/soap/' references distinct types System.String and Microsoft.SharePoint.SoapServer.SoapXml.SoapXmlElement. Use XML attributes to specify another XML name or namespace for the element or types.
One of the MSDN Forums’ answers stated that you could use direct WSDL link (http://url/_vti_bin/sites.asmx?wsdl) and that would work, which it does in the browser but not for CSOM. And besides, I don’t like these kind of errors on one of my environments while other environments work fine.
Turned out someone had disabled HttpGet, HttpPost and HttpPostLocalhost protocols in the web.config of the ISAPI folder (maps to _vti_bin).
Uncomment those lines and your Web Services should be fine again.
January 5, 2012 - 11:22, by Steven Van de Craen
Categories: SharePoint 2010, Search
Posting this for personal reference:
SharePoint 2010 - Configuring Adobe PDF iFilter 9 for 64-bit platforms
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf]
@=hex(7):7b,00,45,00,38,00,39,00,37,00,38,00,44,00,41,00,36,00,2d,00,30,00,34,\
00,37,00,46,00,2d,00,34,00,45,00,33,00,44,00,2d,00,39,00,43,00,37,00,38,00,\
2d,00,43,00,44,00,42,00,45,00,34,00,36,00,30,00,34,00,31,00,36,00,30,00,33,\
00,7d,00,00,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf]
"Extension"="pdf"
"FileTypeBucket"=dword:00000001
"MimeTypes"="application/pdf"
sps2010pdf.reg
January 3, 2012 - 06:24, by Steven Van de Craen
Categories: SharePoint 2010, Excel Services, Office Web Applications
Recently a colleague wanted to display a with Excel Services rendered workbook inside a cross-domain iframe:
- Excel Services: http://intranet/_layouts/xlviewer.aspx?id=%2FShared%20Documents%2FBook1%2Exlsx&DefaultItemOpen=1
- Other domain web site with iframe: http://lux
But because Excel Services and Office Web Apps render a HTTP response header X-FRAME-OPTIONS: SAMEORIGIN this won’t work and you get “This content cannot be displayed in a frame”
Not used to seeing such a straight-forward error :)
I did a bit of investigating but couldn’t find an easy way to configure this through UI or Powershell, so I was left with the following options:
- Strip the header in a reverse proxy (between client and SharePoint server) like Apache or ForeFront
- Remove the header with development of a HttpModule
PermissiveXFrameHeader
I wrote up a quick HttpModule that can be activated by Web Application Feature and will remove the X-FRAME-OPTIONS header no questions asked.
You might want to adapt the code for additional checks on referrer, querystring, client, or similar for conditional removal of the header (see final note below).
Installation and activation
Download from here (Ventigrate Codeplex Repository)
Deploy the WSP (farm solution) to the SharePoint Farm
STSADM -o addsolution -filename Ventigrate.Shared.PermissiveXFrameHeader.wsp
STSADM -o deploysolution -name Ventigrate.Shared.PermissiveXFrameHeader.wsp -allowgacdeployment -immediate
Activate the Web Application Feature to the Web Application referred to in the iframe
Final note
The header was designed to protect against clickjacking. If you intend to use the above solution keep this in mind and plan for it accordingly.
December 27, 2011 - 10:43, by Steven Van de Craen
Categories: jQuery/JavaScript, SharePoint 2010
Here’s a small fix for which I didn’t have time to investigate more properly:
Issue
The User Profile Page of another user shows a link “Add as colleague” when that user isn’t already a colleague:
It seems however that the link behind “Add as colleague” directs to the Default AAM URL rather than the current URL you’re using.
Example:
Zone: Default |
http://internalserver
|
Zone: Intranet |
http://intranet
|
When browsing to the page using http://intranet the link will refer to http://internalserver. This is not the desired behaviour (think mixed authentication or extranet scenario’s).
Quick fix using jQuery
<script type="text/javascript" src="/my/Style Library/js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(function() { var el = $('.ms-my-addcolleague'); if (el.attr('onclick') != undefined) { el.attr('onclick', el.attr('onclick').replace('http:\\u002f\\u002finternalserver:80', '')); } }); </script>
I’m referencing jQuery in the Style Library of the My Site Host, which you need to add or modify the link. I’ve hardcoded the internal URL (default zone public URL), might be better to look that up dynamically but as said this is a quick fix.
You can view the source of your own User Profile Page to find the internal URL for your environment.
You can add this in a Content Editor Web Part to the User Profile page and it should work just fine making the link relative.
Applies to
I’m seeing this issue in a SharePoint 2010 + Service Pack 1 + August 2011 Cumulative Update (14.0.6109.5002). Might be fixed in a later CU or SP.
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.
Next >>