Client Object Model in SharePoint 2010 – Part 1

Client Object Model in SharePoint 2010 is one of the developers dream. It enables developers to
access the SharePoint data from client, the code need not to be deployed in to the server.

Client Object Model can be used in the following three ways.

  • .Net CLR
  • Silverlight Object Model
  • JavaScript

.Net CLR Example:

Create the context to the SharePoint site. No traffic/requests will be made to the server until you call the ExecuteQuery()


try

Source Code

{


ClientContext ctx = new
ClientContext(“http://localhost”);


Web site = ctx.Web;

ctx.Load(site);

ctx.ExecuteQuery();

site.Title = “Update from Client Object Model – Win App”;

site.Update();

ctx.ExecuteQuery();


MessageBox.Show(“Update Succeeded”);

}


catch (Exception ex)

{


MessageBox.Show(“Update Failed “ + ex.ToString());

}


Cannot open database requested by the login the login failed

I got into the below issue, when I try to access the site collection search scopes.

Cannot open database “Uday_SharePoint_SSP_Content” requested by the login. The login failed.
Login failed for user ‘Uday\Uday.Ethirajulu$’. at Microsoft.SharePoint.Portal.Search.Admin.Pages.SearchAdminPageBase.ErrorHandler(Object sender, EventArgs e)
at System.Web.UI.TemplateControl.OnError(EventArgs e)
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP._layouts_viewscopes_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\889c1c0c\c362774f\App_Web_viewscopes.aspx.2a428413.5ohducw0.0.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Troubleshoot issues with Windows SharePoint Services.

 

 

Resolution:

Change the application pool identity from “Network Service”.


Unable to connect to SQL Server session database the connection string was returned by an instance of the IPartitionResolver type

Today, I was playing with authentication providers for setting up the site with anonymous access.

Suddenly the site started throwing the below error. I have no clue what’s wrong on the DB Server, then I restarted the DB Server no luck L

 

Exception:

Exception Type: System.Web.HttpException  Exception Message: Unable to connect to SQL Server session database. The connection string (server=’Uday\Sharepoint’, database=’Uday_Content_DB’) was returned by an instance of the IPartitionResolver type ‘Microsoft.Office.Server.Administration.SqlSessionStateResolver, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’

 

Solution:

    It’s pretty simple close all your browsers and clear the browser cache J

Somehow the session is getting crashed.


WebCast : Client Object Model in SharePoint 2010

I am planning for a webcast with demo in “Client Object Model in SharePoint 2010″ on February 9th 2010.

Register for the event here


List level Validation in SharePoint 2010

In my earlier article, I wrote about column level validation in SharePoint 2010.

List level validation will trigger before saving the content. The validation should return TRUE to save the content.

Library Information List:

I have created sample list Library Information with the following columns.

Validation Scenario:

Due date should be greater than Issue Date.

 

Validation Settings:

Go to List Settings and click on Validation settings.

Specify the validation rule “DueDate > IssueDate”, then specify the error message to be displayed for the user.

Save the Validation Settings.

Create new item in list.

If the validation fails, the error message will be displayed to the user.


User Profile Exception Error while Creating Sample Data in SharePoint 2010 Configuration Wizard

I encountered the following error while running Configuration wizard for SharePoint 2010.

You need to Install the hotfix for Windows Server 2008 R2 / Windows 7. Download here from Microsoft Connect.

   
 


   
 

Error in Log File:

01/09/2010 13:20:05 17 ERR An exception of type Microsoft.Office.Server.UserProfiles.UserProfileException was thrown. Additional exception information: Unrecognized attribute ‘allowInsecureTransport’. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56)

Microsoft.Office.Server.UserProfiles.UserProfileException: Unrecognized attribute ‘allowInsecureTransport’. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56) —> System.Configuration.ConfigurationErrorsException: Unrecognized attribute ‘allowInsecureTransport’. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56)

at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)

at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

at System.Configuration.ConfigurationSectionCollection.Get(String name)

at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client()

at Microsoft.Office.Server.UserProfiles.MossClientBase`1.GetServiceBinding(String endpointConfigurationName)

at Microsoft.Office.Server.UserProfiles.MossClientBase`1.GetChannelFactory(String endpointConfigurationName)

at Microsoft.Office.Server.UserProfiles.MossClientBase`1.get_Channel()

at Microsoft.Office.Server.UserProfiles.MossClientBase`1.ExecuteOnChannel(String operationName, CodeBlock codeBlock)

at Microsoft.Office.Server.UserProfiles.ProfilePropertyServiceClient.ExecuteOnChannel(String operationName, CodeBlock codeBlock)

— End of inner exception stack trace —

at Microsoft.Office.Server.UserProfiles.ProfilePropertyServiceClient.ExecuteOnChannel(String operationName, CodeBlock codeBlock)

at Microsoft.Office.Server.UserProfiles.ProfilePropertyServiceClient.GetProfileProperties()

at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.RefreshProperties(Guid applicationID)

at Microsoft.Office.Server.Utilities.SPAsyncCache`2.GetValueNow(K key)

at Microsoft.Office.Server.Utilities.SPAsyncCache`2.GetValue(K key, Boolean asynchronous)

at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.InitializePropertyCache()

at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.Provision()

at Microsoft.SharePoint.PostSetupConfiguration.EvalModeProvisionTask.ProvisionServiceApplicationsAndProxies()

at Microsoft.SharePoint.PostSetupConfiguration.EvalModeProvisionTask.Run()

at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()


Column Validation in SharePoint 2010

Most of the developers faced issues with column validations in SharePoint 2003/2007.

It is really painful to write the validation using custom approach like javascript or jquery.

SharePoint 2010 provides the following validations in Out of the Box.

  • Column Level Validation
  • List Level Validation

Column Level Validation

While creating new column in list, click on the column validation node.

Specify your validation formula.

e.g.

[FieldName]=”Value”

The formula should return TRUE for validation to PASS.

Create New column in List and Specify the validation Settings.


Create new item in List, Click save to validate.

 

WOW….life is easy with SharePoint.

State Tuned to hear about List level validation in my next post.


CodePlex Release : List Search WebPart

Hi Community,                        

I have contributed List Search WebPart for SharePoint in CodePlex.

Project Description:

                              This Project provides the List Search WebPart for WSS 3.0 / SharePoint 2007. Just add the WebPart to page and specify the list name, filter fields, display fields and criteria.

Simple Interface for Tool Part with advanced features for list search.

Features

  • Ajax Enabled
  • Easy configuration of list
  • Automatically populates List collection in Drop Down List
  • Filter Fields Selection
  • Display Fields Selection
  • Query operator Selection

Configuration Steps

Open the WebPart in Edit Mode.

Filter Fields: Fields to be rendered at page with input box for filter fields.

Display Fields: Fields to be displayed in grid.

 

Condition criteria between the fields

 

When you apply changes the WebPart will render as below:

Please leave your new feature requests here: http://www.mstechblogs.com/Forums/viewtopic.php?f=17&t=2&start=0


How to Create Custom Menu Item in Site Actions

The below sample feature creates new menu item in Site Actions menu, Please replace the GUID in the below code.

Sample Feature File

<?xml version=”1.0″ encoding=”utf-8″?>

<Feature

    Id=”<GUID>”

    Title=”Custom Menu Item”

    Description=” ”

    Version=”1.0.0.0″

    Scope=”Site”

    Hidden=”False” xmlns=”http://schemas.microsoft.com/sharepoint/”>

    <ElementManifests>

        <ElementManifest

            Location=”elements.xml” />

    </ElementManifests>

</Feature>

 

Sample Elements file

<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>

<CustomAction Id=”"

                 GroupId=”SiteActions”

                 Location=”Microsoft.SharePoint.StandardMenu”

                 RequireSiteAdministrator=”TRUE”                

                 Title=”My Blog”

                 Description=” ”

                 Sequence=”1″>

<UrlAction Url=”http://www.mstechblogs.com/sharepoint “/>

</CustomAction>

</Elements>


TreeView Doc Lib V 2.0 in CodePlex

I have released the next version of TreeView Document Library WebPart for SharePoint 2007.

Added features in this release:

 

  • Automatically populates the list of document libraries in dropdownlist in toolpart
  • Collapsed TreeView can be managed from toolpart property
  • Automatically shows the appropriate icons for the files in document library

 

WebPart included as feature in solution package.

Please post your comments or additional feature requests.