Wednesday, June 15, 2011

SharePoint 2010 Data Technologies

If you are a SharePoint developer then for you the most important task is working with and manipulating data. SharePoint 2010 introduced many new Data Technologies that you can take advantage for manipulating Data. It all depends on you, what technology you want according to your requirement and comfort.

Lets discuss Data Technologies in brief. You can use
  • LINQ
  • Server side Object Model
  • Client Side Object Model
  • REST
LINQ is strongly typed entity based programming. In MOSS we used to write CAML as string and Pass it to object like SPQuery. SharePoint 2010 introduces LINQ to write query in strongly typed way and Intelligence and compile time checking. LINQ supports JOINS. LINQ is server side. The first step is to generate entity classes and properties of lists using SPMetal (shipped with SharePoint 2010).
Disadvantage of this is, changing of a list a may break up the whole application and may require to regenerate entity classess. LINQ put some overhead to your code.

Client Object Model:
In MOSS 2007 if you want to write a program on client side there is no choice other than Web Service. SharePoint 2010 introduced new feature Client object model. Using this developers can acees and manipualate data on client computers. This need not requires any deployment on server. Using CO Model we can access data directly from .net Application, Silverlight or from Javascript (ECMAScript). CO Model batches together all its commands and sends all of them together for processing. This will make better performance as less round trips to the server.
Disadvantage: This is not strongly Typed. 

Equivalent objects in Server and Client Object Models

Server Object Model Client Object Model ECMAScript
Microsoft.SharePoint.SPSite Microsoft.SharePoint.Client.Site SP.Site
Microsoft.SharePoint.SPWeb Microsoft.SharePoint.Client.Web SP.Web
Microsoft.SharePoint.SPList Microsoft.SharePoint.Client.List SP.List
Microsoft.SharePoint.SPListItem Microsoft.SharePoint.Client.ListItem SP.ListItem
REST: Representational State Tranfer
In simple words REST is URL based functionality. We can create, query and delete lists and items using standard HTTP protocol. For this data services needs to be installed on Sharepoint Server. REST is implemented in _vti_bin.
will return list of all lists in your site

will return List

will return list item

Sunday, June 12, 2011

Security Token Service (STS) and Sharepoint infinite loop

If you use Sharepoint 2010 with STS you might encounter with a problem infinite loop. I actually created a STS and make it trusted to work with SharePoint 2010. Before i tell you what the problem could be, let me explain how the STS work with Sharepoint.

How STS work?
When any user comes to SharePoint, SharePoint redirects the user to STS Token provider site. Its the responsibility of STS Token issuer site to authenticate user and issue the user a security Token. Security tokens consist of a collection of identity claims (such as a user's name, role, or an anonymous identifier).

Now comes to the problem:
In my scenario, the SharePoint redirects the user redirects to STS provider login page. User enters Username and Password, the user got authencticated and redirected back to SharePoint. But SharePoint redirects back the user to STS Provider. But for STS the user is already authenticated so redirected back again to SharePoint and so on. For SharePoint not a valid Logon Token but for STS provider its a valid logon(As token lifetime was 5 mins). The problem was the Logon Token was expiring when the the users comming to SharePoint. I googled alot and found somewhere that problem is with LogonTokenCacheExpirationWindow

Let me first tell how LogonTokenCacheExpirationWindow works?
  1. If the token lifetime is 5 minutes and LogonTokenCacheExpirationWindow value is 4 minutes, the session cookie will be valid for only 1 minute, and after that minute you will get redirected to authenticatate.
  2. If the token lifetime is 5 minutes and LogonTokenCacheExpirationWindow value is 6 minutes, the session cookie will be delete immidiately because token life is less than expiraryion window.
  3. If the token lifetime is 5 minutes and LogonTokenCacheExpirationWindow value is 5 minutes. This was in my case.
To overcome this problem either increase token lifetime or you can set LogonTokenCacheExpirationWindow to minimum

For second solution open Command Shell and type following commands:

$sts = Get-SPSecurityTokenServiceConfig
$sts.LogonTokenCacheExpirationWindow = (New-TimeSpan –minutes 1)

Tuesday, June 7, 2011

How to use SharePoint Status Bar And Notification?

Sharepoint 2010 have many new UI enhancements. Two enhancements are Status Bar and Notification Area. Both of these can be used to provide useful information to the users. Both of these appears under Ribbon Tab. Status Bar is mostly for something like permanent information. Notifications appears for certain period of time then disappers with some transition effects.

Working with Status Bar
We can provide HTML content to the message. We can add images and styles. The status bar can have one of the pre defined colors(red, green, blue, yellow) depending on priority of the immage. For example if message is very important we can show it in red.
Status bar is exposed SharePoint JavaScript API defined inside sharepointroot\templates\layouts\SP.js

Methods exposed by SP.UI.Status
  • addStatus: Accepts three parameters Title, Message as HTML , show at begining as boolean. Returns status ID
    sid = SP.UI.Status.addStatus(strTitle, htmlMessage, boolatBegning)
  • removeStatus: removes status specified by status id.
  • removeAllStatus: Removes all Status bar messages. Pass true if you want to hide bar.
  • setStatusPriColor: Takes two parameter status id and colorsetStatusPriColor(sid,"red")
<script langauage="javascript">
var statusID;

function ShowStatus()
   statusID = SP.UI.Status.addStatus("Information","This is my first status bar",true);

The above script will show status bar in red.

SharePoint 2010 Status Bar
SharePoint 2010 Status Bar
We can show status bar in diffrent colors depending on importance of message. If very important then use red, if warning message in then use yellow color.

Working with Notifications

Notification Area usually appears rigth corner below the ribbon. this is used when the users needs to to updated for the processess being performed. Like saving content, saved content.

Methods exposed by SP.UI.Notify
  • addNotification: Accepts two parameters Message as html and a boolean value indicating sticky or not. If second parameter is passed as false then notification disappers after 5 seconds. This method returns notification id.
  • removeNotification: Removes notification specified by notification id.
<script type="text/javascript">

notificationID = SP.UI.Notify.addNotification(
var notificationID;function ShowNotification() {"This is my first notification", true, " Tooltip", "Helloworld");
The above script will show sticky Notification. Pass second parameter as false in above script to hide Notification after 5 seconds.

SharePoint 2010 Notification
SharePoint 2010 Notification

Popular Posts