【发布时间】:2017-05-11 14:37:00
【问题描述】:
我在遵循本指南时遇到了困难
http://dotnetbyexample.blogspot.co.uk/2011/03/sharepoint-client-object-model-sites.html
我已按照建议创建了帮助程序类:
namespace TestSharepoint
{
public class SharepointHelper
{
private ClientContext clientContext;
private Web rootWeb;
public SharepointHelper(string url, string username, string password)
{
clientContext = new ClientContext(url);
var credentials = new NetworkCredential(username, password, "oshirowanen.com");
clientContext.Credentials = credentials;
rootWeb = clientContext.Web;
clientContext.Load(rootWeb);
}
}
}
但是,我不想创建另一个站点,因为我已经有一个站点,所以我想通过检索现有站点标题来测试下一部分:
public Web GetWebByTitle(string siteTitle)
{
var query = clientContext.LoadQuery(
rootWeb.Webs.Where(p => p.Title == siteTitle));
clientContext.ExecuteQuery();
return query.FirstOrDefault();
}
并将其添加到表单加载事件中:
var sh = new SharepointHelper("https://sharepoint.oshirowanen.com/sites/oshirodev/", "sharepoint_admin_user", "sharepoint_admin_password");
var w = sh.GetWebByTitle("Oshirowanen SharePoint");
Console.WriteLine(w.Title);
我感到困惑的是,为什么我要输入我想要获得标题的网站的标题???所以我认为我没有正确使用它?
我得到的错误是:
An unhandled exception of type 'System.NullReferenceException' occurred in SharePointProgramming.exe
Additional information: Object reference not set to an instance of an object.
知道我做错了什么吗?
我使用的用户名和密码具有完全的 SharePoint 权限。
我正在使用 Visual Studio 2013、C#、.NET 4.0 和 SharePoint 2010。
【问题讨论】:
-
确保“Oshirowanen SharePoint”是网站集 /sites/oshirodev/ 的子网站。如果 "Oshirowanen SharePoint" = rootWeb 而不是在 rootWeb.Webs 集合中可见。
标签: c# visual-studio-2013 sharepoint-2010 .net-4.0