Wednesday 12 November 2014

Server object model architecture

Server Architecture

The following diagram shows the Windows SharePoint Services server architecture in relation to the collections and objects of the Microsoft.SharePoint.Administrationnamespace.
Server Architecture
  1. The SPFarm object is the highest object within the Windows SharePoint Services object model hierarchy. The Servers property gets a collection representing all the servers in the deployment, and the Services property gets a collection representing all the services.
  2. Each SPServer object represents a physical server computer. The ServiceInstances property provides access to the set of individual service instances that run on the individual computer.
  3. Each SPService object represents a logical service or application installed in the server farm. A service object provides access to server farm-wide settings of the load-balanced service that a respective service instance implements. Derived types of the SPService class include, for example, objects for Windows services, such as the timer service, search, Microsoft SQL Server, the database service, etc. and also objects for Web services, such as Windows SharePoint Services or services in the Microsoft Office system.
  4. An SPWebService object provides access to configuration settings for a specific logical service or application. The WebApplications property gets the collection of Web applications that run the service.
  5. An SPDatabaseServiceInstance object represents a single instance of a database service running on the server computer. The SPDatabaseServiceInstance class derives from the SPServiceInstance class and thus inherits the Service property, which provides access to the service or application that the instance implements. The Databasesproperty gets the collection of content databases used in the service.
  6. Each SPWebApplication object represents a load-balanced Web application based in Internet Information Services (IIS). The SPWebApplication object provides access to credentials and other server farm wide application settings. The Sites property gets the collection of site collections within the Web application, and theContentDatabases property collection of content databases used in the Web application. The SPWebApplication class replaces the obsolete SPVirtualServer class; but it can still be helpful to think of a SPWebApplication object as a virtual server; that is, a set of one or more physical servers that appear as a single server to users.
  7. An SPContentDatabase object inherits from the SPDatabase class and represents a database that contains user data for a SharePoint Web application. The Sites property gets the collection of site collections for which the content database stores data, and the WebApplication property gets the parent Web application.
  8. An SPSiteCollection object represents the collection of site collections within the Web application. The Item property or indexer gets a specified site collection from the collection, and the Add method creates a site collection within the collection.

Site Architecture

The following diagram shows the Windows SharePoint Services site architecture in relation to the collections and objects of the Microsoft.SharePoint namespace.
Site Achitecture
  1. Each SPSiteobject, despite its singular name, represents a set of logically related SPWeb objects (see below). Such a set is commonly called a "site collection," but SPSiteis not a standard Microsoft .NET collection class, in contrast to SPWebCollection. Rather, it has members that can be used to manage the site collection. The AllWebsproperty provides access to the SPWebCollection object that represents the collection of all Web sites within the site collection, including the top-level site. TheSPSite.OpenWebmethod of the SPSite class returns a specific Web site.
  2. Each site collection includes any number of SPWeb objects, and each object has members that can be used to manage a site, including its template and theme, as well as to access files and folders on the site. The Webs property returns an SPWebCollection object that represents all the subsites of a specified site, and the Lists property returns an SPListCollection object that represents all the lists in the site.
  3. Each SPList object has members that are used to manage the list or access items in the list. The GetItems method can be used to perform queries that return specific items. The Fields property returns an SPFieldCollection object that represents all the fields, or columns, in the list, and the Items property returns an SPListItemCollectionobject that represents all the items, or rows, in the list.
  4. Each SPField object has members that contain settings for the field.
  5. Each SPListItem object represents a single row in the list.

Thursday 18 September 2014

Create Page-layout Using SharePoint Designer

We can create page layout in SharePoint designer 2010 very easily. First open your site inSharePoint designer 2010 and then from the Site Objects section from the left side click on Page Layouts as shown in the figure below.
Then from the ribbon click on New Page Layout as shown in the figure below:


Then from the New Page Layout Dialog box Select the content type group, content type name, url name, title as shown in the figure below, then click on OK.

This will create your pagelaout, now to add web part zones or to add different sections modify as below.



<%@ Page language="C#"   Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" meta:webpartpageexpansion="full" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<table>
<tr>
<td><WebPartPages:WebPartZone id="MyTopZone" runat="server" title="TopZone"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</td>

</tr>
<tr><td>
<WebPartPages:WebPartZone id="MyMiddleZone" runat="server" title="MiddleZone"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</td></tr>
<tr><td>
<WebPartPages:WebPartZone id="MyLeftZoneFirst" runat="server" title="LeftZoneFirst"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</td>
<td>
<WebPartPages:WebPartZone id="MyLeftZoneMiddle" runat="server" title="LeftZoneMiddle"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</td>
<td>
<WebPartPages:WebPartZone id="MyLeftZoneRight" runat="server" title="LeftZoneRight"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</td>
</tr>
</table>
</asp:Content>

Here I have added 3 sections, top, middle and lower. And my top and middle section contains one web part zone and my lower section contains 3 web part zone.

Then you can publish the page layout by right click on the page layout and click on Checkin. And your name page will look like below image

Monday 8 September 2014

Server object model CRUD

   Item insert, update,delete and field update.

Insert item


Spsite site    =  spcontext.current.site;
SPWeb web = site.openweb();
            SPList list = web.Lists["Employee"];
            SPListItem listItem = list.Items.Add();
            listItem["Title"] = "Betty";
            listItem["Birthday"] = "1/1/1990";
            listItem["Male"] = 1;
            listItem["Position"] = "Tester";
            listItem.Update();   


    Update item

syntax:1


SPSite site = SPContext.Current.Site;
                    SPWeb web = site.OpenWeb();
                    web.AllowUnsafeUpdates = true;
                    SPList list = web.Lists["BritCustomers"];
                    SPListItem item = list.GetItemById(Convert.ToInt32(TextBox4.Text));
                    item["First Name"] = TextBox1.Text;
                    item["Last Name"] = TextBox2.Text;
                    item["Age"] = Convert.ToInt32(TextBox3.Text);
                    item.Update();                                      //         item.Delete(); (if u want to teh delete the item use  this )
                    Label5.Text = "Data Successfully Updated";
                    TextBox1.Text = string.Empty;
                    TextBox2.Text = string.Empty;
                    TextBox3.Text = string.Empty;

                    TextBox4.Text = string.Empty;



syntax:2


SPsite site    =  SPcontext.current.site;
SPWeb web = site.openweb();
 SPList list = web.Lists["Employee"];

SPListItem Item = list.GetItemById(ItemID);

SPListItem itemToAdd = list.Items.Add();

            string listItemId= listitem.ID;


SPListItem item= list.GetItemById(listItemId);

            item["Birthday"] = "Changed Description";
            item.Update();


  Delete item


SPsite site    =  SPcontext.current.site;
SPWeb web = site.openweb();
 SPList list = web.Lists["Employee"];

            string listItemId= listitem.ID;

SPListItem itemToDelete = list.GetItemById(listItemId);
            itemToDelete.Delete();


examlpe2:

Edit an item
             for (int i = 0; i < itemCol.Count; i++)
            {
                SPListItem item = itemCol[i];
                if(item["ID"].ToString() == "2"// Find an item by ID then updating it
                {
                    item["Title"] = "Linda";
                    item["Birthday"] = "1/2/1990";
                    item["Male"] = 0; //the Yes/No field type, 0 refers to female and 1 refers to male
                    item["Position"] = "Tester";
                    item.Update();
                    break;
                }                
            }

Delete an item
          list.Items.DeleteItemById(7); 


SPField Update:

SPSite site = SPContext.Current.Site;
                    SPWeb web = site.OpenWeb();
                    web.AllowUnsafeUpdates = true;
                    SPList list = web.Lists["BritCustomers"];

                    SPField field = list.Fields["Age"];
                    field.Title= "britcustomerage";

                    field.Update();








   

Friday 5 September 2014

Client Object model CRUD

The Client OM works by sending an XML Request. The server will return a JSON response which is converted to the appropriate Object Model.

Supported Languages

Following are the programming language/platforms supported for Client Object Model:
  • .NET Languages (C#, VB.NET etc.)
  • Silverlight
  • Scripting Languages (JavaScript, Jscript)

Core Assemblies

There are two assemblies to be referred for working with the Client Object Model.
  1. Microsoft.SharePoint.Client.dll
  2. Microsoft.SharePoint.Client.Runtime.dll
These assemblies can be found in the 14 Hive folder: %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI.

Classes inside Client Object Model

In C#, comparing with classes of the Server Object Model, we can see that Client Object Model has similar classes with a suffix in the namespace and no SP prefix in the class name.
For example: SPSite in the Server Object Model is represented in the Client OM as Site with namespace Microsoft.SharePoint.Client.
Client Object ModelServer Object Model
Microsoft.SharePoint.Client.ClientContextSPContext
Microsoft.SharePoint.Client.SiteSPSite
Microsoft.SharePoint.Client.WebSPWeb
Microsoft.SharePoint.Client.ListSPList

 

More Examples with Client Object Model

Here I would like to list some examples using the Client Object Model. For starting with the examples, please do the following:
  1. Create a Windows Application
  2. Change the Target Framework to .NET 4.0
  3. Add reference to Microsoft.SharePoint.Client, Microsoft.SharePoint.Client.Runtime
Before continuing with the examples, please ensure the site has valid data items in the Tasks list. We will be changing the data items during our session.

1. Get List Items

Here we are querying the list items of the Tasks list.
ClientContext context = new ClientContext(ServerText.Text);
List list = context.Web.Lists.GetByTitle("Tasks");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection items = list.GetItems(query);

context.Load(list);
context.Load(items);

context.ExecuteQuery();
After executing the code, the result can be stored into a DataTable as shown below.
DataTable table = new DataTable();
table.Columns.Add("Id");
table.Columns.Add("Title");

foreach (ListItem item in items)
    table.Rows.Add(item.Id, item["Title"]);

datagrid.DataSource = table;
On my machine, the data retrieved is shown below:

2. Update List Items

Here I would like to show the modification code. All the titles are appended with two asterisks whose IDs are even number.
ClientContext context = new ClientContext(ServerText.Text);
List list = context.Web.Lists.GetByTitle("Tasks");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";
ListItemCollection items = list.GetItems(query);

context.Load(items);

context.ExecuteQuery();

foreach(ListItem item in items)
    if ((item.Id % 2) == 0)
    {
        item["Title"] += "**";
        item.Update();
    }

context.ExecuteQuery();
After executing the query, please refresh the data grid using the Get Data button. You can see the following result.

You can see that the Titles are modified for those with even number IDs.

 

3.Insert an item

Here we can try inserting a new item into the Tasks list.
ClientContext context = new ClientContext(ServerText.Text);
Web web = context.Web;

List list = web.Lists.GetByTitle("Tasks");

ListItemCreationInformation newItem = new ListItemCreationInformation();
ListItem listItem = list.AddItem(newItem);
listItem["Title"] = "New Item Created through C#";
listItem.Update();

context.ExecuteQuery();
You can see that we are using a new class named ListItemCreationInformation along with the ListItem class. This information will be recorded and passed to the server once the ExecuteQuery() method is called.
On executing the above code and retrieving the results, you can see the output as below:

6. Update an Item

The Update operation is next in the series of the CRUD pattern. Already we have seen updating the Title. Here you can see how to update the Status.
ClientContext context = new ClientContext(ServerText.Text);
List list = context.Web.Lists.GetByTitle("Tasks");
CamlQuery query = new CamlQuery();
query.ViewXml = "<View/>";

ListItemCollection listItems = list.GetItems(query);

context.Load(listItems);

context.ExecuteQuery();

ListItem item = listItems[listItems.Count - 1];
item["Status"] = "In Progress";
item.Update();

context.ExecuteQuery();
On executing the code, you can see that the last item was updated.

7. Delete an Item

Now we can try deleting an item from the List. Here is the code to achieve that.
ClientContext context = new ClientContext(ServerText.Text);
List list = context.Web.Lists.GetByTitle("Tasks");

ListItemCollection listItems = list.GetItems(new CamlQuery() { ViewXml = "<View/>" });
context.Load(listItems);
context.ExecuteQuery();

listItems[listItems.Count - 1].DeleteObject();
context.ExecuteQuery();
We need to call the DeleteObject() method of the item followed by the ExecuteQuery().

 

10. Specifying Credentials

You can specify user credentials while accessing the SharePoint server. The property Credentials is for this purpose.
ClientContext context = new ClientContext(ServerText.Text);
context.Credentials = new NetworkCredential("User", "Password");

Web web = context.Web;
context.Load(web);

context.ExecuteQuery();
MessageBox.Show(web.Title);

Sunday 24 August 2014

Document Set

How to create document set in SharePoint 2010

Document Set is used to manage set of documents as a single object
It is a new feature introduced in Share Point 2010.

Advantages of using Document Set in Share Point 2010.

Work Flow can be associated to a whole document set.
We can upload project related documents in Document set.
We can maintain the version of all related documents using Document set.
We can manage permissions easily.
We can able to set customizable welcome page for Document Set.
We can download all the zip files easily by using Document Set.
There is no limit that no of documents exit in Document set.

Folders also used to manage set of documents as a single object.
But for folders we can't start work flow.
Customizable welcome page for all document sets.

Now I will Explain How to Create Document Set.


Navigate to your share point Site Actions->Site Settings.

Navigate to Site Collection Administration ->Site collection features


By default I will not active, click on that feature to Activate




 Now I am creating a document library I give name as Document Set.
                             

Click on that Created Document Library ->Navigate to Library Settings.
                              
Navigate to General settings->Click on Advanced Settings
                         

Allow Management of content types to Yes.
              

Click OK.

In Library settings page we can able to see Content Types.
Click on Add from existing site content types.
  

In Available site Content Types->Select Document Set->Add  
                   
Click OK.
Now we want to give name for Document set.
Navigate to Library settings->Content Types->Click on Document Set
                        

Click on Name and Description tab->Enter Name ->Click OK




 Now click on Created document library Name → Document tab



Go to New Document->
Now we are able to see the created document set with name Share Point Project
                               
Click on that Share point Project ,I am give name as Project Documents and Click Ok.

Now are able to seen the created document set



Now are able to seen the created document set

Click on that Project Documents.
Click on documents tab->Click on Upload Document.

Now we are able to see my uploaded documents.

- See more at: http://www.dotnetsharepoint.com/2013/08/how-to-create-document-set-in.html#.U_rR7_mSwvx