Sunday, May 5, 2013

Friday, October 1, 2010

SharePoint 2010 - Silverlight Client Object Model
Introduction:

Recently, I worked on a project based on SharePoint 2010 Beta. While providing solution to client, we came across Silverlight Client Object Model (OM). Microsoft SharePoint Foundation 2010 has it as part of new Client API.


As it is new to us, few questions come to our mind: How to use it? What are the basic steps to make it work? What objects, properties and methods available for use? We dig out the answer for the same & made use of it in our project successfully. I’m not the only one to have such questions, hence this post. Hope this will help others also.


Silverlight Client OM helps us develop client-side solutions. To use Silverlight Client OM, one needs to refer two DLL files (assemblies) in the application: Microsoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll. The assemblies are located on SharePoint Server machine at “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin” folder.


To start coding, one must add “using” statement for Microsoft.SharePoint.Client namespace. This core namespace provides types and members for working with SharePoint site-collection, sites, list data, and security. The Client API does not provide any admin objects or objects with scope higher than site collection.


All client objects inherit Microsoft.SharePoint.Client.ClientObject class & collections are inherited from Microsoft.SharePoint.Client.ClientObjectCollection class.

Client Object and Value Object:

All types, inheriting from ClientObject class, are referred as client objects whereas types, inheriting from ClientValueObject class, are value objects. Value objects have only properties & no methods. Do not conflict with Value Type concept of .NET Framework.

Scalar Property:

Property, returning value object is referred as scalar property.

Frequently Used Types:




All these types belong to “Microsoft.SharePoint.Client” namespace. “ClientContext” is the central object to gain access to Client OM.
Initializing Client Context:
ClientContext object requires the URL of site as a parameter to the constructor.

e.g. ClientContext context=new ClientContext(“http://www.somesite.com/”);

Silverlight web part when host the Silverlight application, they pass the URL of site as a initialization parameter (InitParams) to the application.

Properties of ClientContext:

Property Description

Site Retrieves site-collection associated with current context

Web Retrieves context specific site.

Current Static property representing current context object.


By using these properties, one can access client objects up to the site-collection level.


Methods of ClientContext:
Below are the three important methods of ClientContext.

Method Description
Load Used to load the query for the action.

LoadQuery Used to load the LinQ query & to perform queryable load. (see below)

ExecuteQueryAsync Used to send the query to the server. This is an asynchronous operation.





Client Objects do not have associated data until data retrieval is performed. Data retrieval is done using the Load & Execute methods of ClientContext. Data retrieval can be executed in two ways: In-place load & queryable load.

Queryable load uses “LoadQuery” method of context object & returns enumerable generic collection. It means, retrieved data goes to result collection. It does not load the data in the object itself.

In-place load uses “Load” method of context & loads data to client objects. That means, retrieved data will be loaded to client objects.

LinQ has two forms of data projection syntax: query syntax & method syntax. “LoadQuery” should be used when using query syntax. For method syntax, either of the load methods works. LinQ in Client OM is LinQ-to-Object.

Once the query is loaded to the context, use ExecuteQueryAsync method to send the action query to server to get data. ExecuteQueryAsync has two parameters as delegate objects: ClientRequestSucceededEventHandler & ClientRequestFailedEventHandler.
ClientRequestSucceededEventHandler specifies the method to be executed after successful completion of ExecuteQueryAsync whereas ClientRequestFailedEventHandler invokes method on failure of query execution.

Steps for Data Retrieval
1. Get ClientContext object.
2. Specify the object to retrieve data using object model.
3. Load the object either using in-place load or queryable load.
4. Execute the query.
5. Write code to process object in a method which will execute after successful invocation query.
Data Retrieval Example:




using System;using Microsoft.SharePoint.Client;namespace Example.Silverlight.ClientOM{ClientContext context;Web site;public MainPage(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){context = ClientContext.Current;site = context.Web;context.Load(site,website=>website.Title);context.ExecuteQueryAsync(OnSuccess, null);}private void OnSuccess(object sender, ClientRequestSucceededEventArgs e){MessageBox.Show(“Site Title:”+site.Title);}}


I know that this post requires few more examples. But due to time-constraint it is not possible. I'll update the post with few more samples and updates in few days. So visit again!!!

Saturday, July 24, 2010

Global Warming : Causes and Effects



People are using many cars, aeroplanes, trains and power stations. People are also cutting down lots of trees. Trees clean the air.



As the earth is getting hotter, disasters like hurricanes, droughts and floods are getting more frequent.

Global warming is a very difficult problem to fix. People agree on what to do about it. Wasting energy is a bad thing to do, but some people think that the government should make laws about it, while other people think it should be up to each person or business to decide what to do. Scientists agree that the burning of fossil, fuels are causing global warming. Since these fuels are burned for energy and everyone uses energy, every one can help stop global warming just by using less energy. Think about the things you use each day that use energy. The lights in your house, the TV and the computer, the washing machine, the dishwasher and dryer all use gas or electricity. Every time you ride in your car, it uses gas.



Global warming is bad. Cars pollute the air. Methane is released into the atmosphere from a dozen major sources that are both natural and man made. Natural release of methane is primarily from wetlands, agricultural lands, termites and the ocean. Non-organic releases are based from landfills, farm animals, waste treatment, and sewage treatment.



Scientists agree that the burning of fossil fuels like oil and coal cause greenhouses gases to escape into the air and that these gases are causing most of the warming. Another cause is deforestation (cutting down trees). Trees soak up carbon dioxide, one of the greenhouse gases, from the air. Global warming refers to the increase of the Earth’s average surface temperature, due to a build-up of greenhouse gases in the atmosphere. If the warming gets worse, as scientists expect, there may be some kinds of plants and animals that become extinct because they can’t move to new homes.



The Earth is wrapped in a blanket of air called the ‘atmosphere’, which is made up of several layers of gases. The gases in the atmosphere stop some of the heat from escaping into space.
The windows of a greenhouse play the same role as the gases in the atmosphere, keeping some of the heat inside the greenhouse.



Some of the activities of man produce greenhouse gases. A lot of scientists agree that man’s activities are making the natural greenhouse effect stronger.
If we carry on polluting the atmosphere with greenhouse gases, it will have very dangerous effects on the earth. Winter and summer temperatures will increase and the weather will be warmer. Some places will be at risk from drought.