如何在执行ClientContext.ExecuteQuery前检查Sharepoint的连通性
本文关键字:检查 Sharepoint 连通性 ExecuteQuery 执行 ClientContext | 更新日期: 2023-09-27 18:03:26
我是sharepoint的新手。在ClientContext.ExecuteQuery.
之前检查Sharepoint站点连接的最快和最有效的方法是什么?ClientContext ctx = new ClientContext(ConfigurationManager.AppSettings["sharepoint siteUrl"]);
float pageLoadTime = getPageLoadTime(ctx);
if(pageLoadTime > 0.5)
{
MessageBox.Show("Sharepoint site is not available!");
return;
}
//do very heavy query
....
ctx.ExecuteQuery();
没有这样的标准方法。但是您可以像下面的代码
那样实现它 using (ClientContext sourceContext = new ClientContext("Sharepoint Url"))
{
try
{
sourceContext.ExecuteQuery();
List list = sourceContext.Web.Lists.GetByTitle("Test");
ListItemCollection itemColl = list.GetItems(CamlQuery.CreateAllItemsQuery());
sourceContext.Load(itemColl);
sourceContext.ExecuteQuery();
}
catch (System.Net.WebException ex)
{
if (ex.Message == "The remote server returned an error: (404) Not Found.")
{
Console.WriteLine("SharePoint not available");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
因为"ExecuteQuery"是通过Client连接到SharePoint的方法。SVC WCF服务