[英]How do you create a page using the API for sharepoint 2010?
我剛剛開始使用 Sharepoint Foundation 2010 並且我正在嘗試從 c# 編寫 function 以將頁面添加到站點。
我有一些代碼可以創建一個新站點,但我似乎找不到任何有關使用客戶端 object model 將頁面添加到現有站點的文檔。
這可能是一個簡單的問題,但如果有人可以幫助我,我將不勝感激。
謝謝。
更新
這是我到目前為止所擁有的:
private void createPage()
{
ClientContext context = new ClientContext(url);
Site siteCollection = context.Site;
Web site = context.Web;
List pages = site.Lists.GetByTitle("Pages");
FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = "NewPage";
fileCreateInfo.Content = System.Text.Encoding.ASCII.GetBytes("Test");
context.Load(pages.RootFolder.Files.Add(fileCreateInfo));
context.ExecuteQuery();
context.Dispose();
}
但我得到一個服務器異常“列表'頁面'在帶有 URL 的站點上不存在”
這就是我最終添加頁面的方法。 基本上我只需要找到合適的列表標題。 這些只是站點上文檔庫的名稱。
private void createPage()
{
ClientContext context = new ClientContext(URL);
Site siteCollection = context.Site;
Web site = context.Web;
List pages = site.Lists.GetByTitle("Site Pages");
Microsoft.SharePoint.Client.
FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = "NewPage.aspx";
context.Load(pages.RootFolder.Files.Add(fileCreateInfo));
context.ExecuteQuery();
context.Dispose();
}
本准則適用於我。 它使用內容測試創建一個頁面(“NewPage.aspx”)。
private void createPage()
{
ClientContext context = new ClientContext(URL);
Site siteCollection = context.Site;
Web site = context.Web;
List pages = site.Lists.GetByTitle("Site Pages");
Microsoft.SharePoint.Client.
FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = "NewPage.aspx";
fileCreateInfo.Content = System.Text.Encoding.ASCII.GetBytes("Test");
context.Load(pages.RootFolder.Files.Add(fileCreateInfo));
context.ExecuteQuery();
context.Dispose();
}
如果您正在談論創建新網站頁面,我建議您查看本教程:
花點時間確保您確實想通過代碼添加它。 作為最近開始使用 SharePoint 進行開發的人,我可以告訴您,在使用 Object Model 時,學習曲線相當陡峭。 此外,通過 UI 很容易完成的任務使用代碼可能會非常困難。
祝你好運!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.