2016-08-22 14 views
0

私は非常にsharepointに新しいです。 ClientContext.ExecuteQueryの前に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(); 

答えて

0

このような標準的な方法はありません。 「のexecuteQueryは」Client.svcのWCFサービスを通じてSharePointに接続する方法であるので、しかし、あなたは、コード

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

を次のようにこれを達成することができます。

希望します。

+0

こんにちは、Ahshay、ありがとうございます。タスクを実行する前に "Ping"を使用して接続を確認する必要があるかもしれません。 –

関連する問題