Hello world(获取网站标题)

所有版本的 SharePoint 都基于站点(SPSite(SSOM) 或站点(CSOM))和 Web(SPWeb(SSOM) 或 Web(CSOM))。虽然网站确实包含应用于其子网站的元数据和功能,但它不会在 UI 中呈现。Web 是基本构建块,用于向访问该站点的用户呈现 UI。所有站点都有一个根网站,其中包含文档库等信息和/或元数据。此示例显示了在虚拟路径 sites 下获取位于服务器 MyServer 上的 Web 的基本调用。

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);
            }
        }
    }
}