sharepoint Hello world (getting site title)


Example

All versions of SharePoint are based around Sites (SPSite (SSOM) or Site (CSOM)) and Webs (SPWeb(SSOM) or Web(CSOM)). A site is not rendered in the UI although it does contain metadata and features that are applied to its children. A web is the basic building block that renders a UI to the user accessing the site. All Sites have a root web that holds information and/or metadata like Document Libraries. This example shows a basic call to fetch the web located on the server MyServer under the virtual path sites.

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
    class RetrieveWebsite
    {
        static void Main()
        {
            // This is the URL of the target web we are interested in.
            string siteUrl = "http://MyServer/sites/MySiteCollection";    
            // The client context is allows us to queue up requests for the server
            // Note that the context can only ask questions about the site it is created for
            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                // To make it easier to read the code, pull the target web
                // context off of the client context and store in a variable
                Web oWebsite = clientContext.Web;
                // Tell the client context we want to request information about the
                // Web from the server    
                clientContext.Load(oWebsite);    
                // After we are done creating the batch of information we need from the sever,
                // request the data from SharePoint
                clientContext.ExecuteQuery();
                // Print the results of the query    
                Console.WriteLine("Title: {0} Description: {1}", oWebsite.Title, oWebsite.Description);
            }
        }
    }
}