I created a List Event Receiver for my custom List Definition and wanted to set a view list properties programmatically in the EventReceiver. It worked perfectly in SharePoint 2010 but not in SharePoint Online.

To get the list I used the SPListEventProperties.List, but this object was causing some issues in SharePoint Online. I solved it by using the SPListEventProperties.Web.Lists[listname].

Code before:

SPList list = properties.List;

//enable content types
list.ContentTypesEnabled = true;


Code after:

SPList list = properties.List;
 SPWeb web = properties.Web;

// Re-opening the list, seems to be necessary because SharePoint Online has some sort of bug or timing issue.
 list = web.Lists[list.Title];

// enable content types
 list.ContentTypesEnabled = true;


I’m creating a sandboxed web template for Office 365. I’m adding several web parts to a page and it’s working fine until I add Social web parts, like a Note Board or Tag Cloud. When I add one of these to a page I receive the famous “Cannot import Web Part” error upon deploying a site with this template.

The problem is that SharePoint exports the web part definition as a .webpart (v3) file. As it seems, Social Collaboration Web Parts don’t work well together with a v3 web part definition. When you change it to an old v2 (.dwp) definition it works perfectly.

So, this doesn’t work:

 <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
 SocialCommentWebPart, Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
 <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
 <property name="Height" type="string" />
 <property name="AllowZoneChange" type="bool">True</property>
 <property name="AllowConnect" type="bool">True</property>
 <property name="ExportMode" type="exportmode">All</property>
 <property name="HelpUrl" type="string" />
 <property name="Hidden" type="bool">False</property>
 <property name="TitleUrl" type="string" />
 <property name="WebPartPropertyDisplayItems" type="int">20</property>
 Enable users to leave short, publicly-viewable notes about this page.
 <property name="AllowHide" type="bool">True</property>
 <property name="ChromeState" type="chromestate">Normal</property>
 <property name="AllowMinimize" type="bool">True</property>
 <property name="Title" type="string">Posts</property>
 <property name="ChromeType" type="chrometype">TitleOnly</property>
 <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
 <property name="Width" type="string" />
 <property name="WebPartPropertySpecifiedAddress" type="string" null="true" />
 <property name="HelpMode" type="helpmode">Modeless</property>
 <property name="CatalogIconImageUrl" type="string" />
 <property name="AllowEdit" type="bool">True</property>
 <property name="TitleIconImageUrl" type="string" />
 <property name="Direction" type="direction">NotSet</property>
 <property name="AllowClose" type="bool">True</property>
 <property name="WebPartPropertyAllowNewComment" type="bool">True</property>

And this works:

 <Description>Displays a list of your colleagues and their recent changes.</Description>
 <Assembly>Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

Note the change from “http://schemas.microsoft.com/WebPart/v3” to “http://schemas.microsoft.com/WebPart/v2“. Also note the absence of the <webParts> tag, which isn’t allowed in the v2 web part definition.

In this sample I’ve taken the Note Board Web Part (SocialCommentWebPart), but you can use whatever web part you want by changing the TypeName.