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