Monday, 7 May 2012

SharePoint 2010 tips for dealing with preformance issues

It's nice to have all performance related info in one place with content updated regularly.

Visual Studio 2010 tabs in separate windows

Every day is a school day.

After years with VS I started using this feature more and more.
Just drag and drop tab, with for example code, anywhere outside Visual Studio window and it will behave like floating tab.

It's especially useful when working on more than one screen.

SharePoint 2010 browser support

According to Microsoft all latest versions of browsers are supported.
http://blogs.technet.com/b/tothesharepoint/archive/2012/04/04/updates-to-plan-browser-support.aspx

Are they really? Someone compared them and guess what - 'supported' can be widely interpreted.
http://davidlozzi.com/2012/04/17/sharepoint-browser-support-all-latest-browsers-supported-really/
 

Project Glass - Google Glasses

Recently Google made it to the top of every single geek website with it's concept (and prototype?) of glasses.


To be honest I was impressed with the idea and it's potential. Imagine your phone, camera, internet browsing, emails, reading books, watching movies, VR maps and location based notifications etc. and all hands free (they just need to come up with better idea about typing - I can't see myself standing in the train and trying to reply to an email by saying out loud each word of the message... And how would you like to copy/paste links and media?)
Then I remembered I've seen those wicked gaming helmets so you can feel like you're in the game - kind of 3D/VR thing - of course you had to have special games for it. But wait a second, that was 10-15 years ago...

 Someone surely made Project Glass before or at least failed trying. So I Googled it and guess what?

http://www.wired.com/gadgetlab/2012/04/6-glasses-with-integrated-displays-that-you-can-buy

Looks like they are not the first but definitely the most advertised.

By the way, some people think it may be difficult to adapt to it and yes - adverts, they have a point there:



 

SharePoint 2010, event receivers and Save Conflict error.


Recently I tried to modify all images right after they were uploaded to the library.
I went for ItemAdded event receiver to be sure all metadata etc is there. Then I hit this error:

Save Conflict.  Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.<nativehr>0x81020037</nativehr><nativestack></nativestack>

Of course ItemAdded event is asynchronous so there is a big chance SharePoint, workflow or other event receiver was still changing something and I was caught up in the middle of this or my changes executed other event receivers like ItemUpdating.


So to fix it there are t hings that need to be done. 

1) Make things synchronous.
In my case asynchronous event has to be made synchronous and fortunately SharePoint 2010 introduce Synchronization (both in CAML and code)

So simple

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers >
      <Receiver>
          [...]
       <Synchronization>Synchronous</Synchronization>
          [...]
      </Receiver>
  </Receivers>
</Elements>


or

[...]  
eventReceiver.Synchronization =
         SPEventReceiverSynchronization.Synchronous;
[...]


will solve it.

2) Disable event firing
To avoid other event receivers to fire we need to change EventFiringEnabled flag. You can do it in various different ways but I particularly like this approach: http://buyevich.blogspot.co.uk/2010/10/disableeventfiring-is-obsolete-in.html

This way you won't fire other events (unless necessary) and won't end up in the loop when using ItemUpdating or ItemUpdated.

Enabling Session State in SharePoint 2010

Just a quick note to myself - use PowerShell to enable Session State in SharePoint 2010. 

If you want to do it manually you have to change web.config on all WFEs as well as enable SharePoint's Session State Service in the farm. You'll get error below if you forget just one step: 

Error: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the section in the application configuration. 

How to do it? Use Enable-SPSessionStateService, 
for example: Enable-SPSessionStateService -DefaultProvision  

More about  Enable-SPSessionStateService on MS sites: http://technet.microsoft.com/en-us/library/ff607857.aspx