🛠️
CSOM の WebTemplate には Path が入ってこない
事象について説明するために以下のコードを実行します。
public static class Program
{
private static void Main(string[] args)
{
var siteUrl = "{{site-url}}";
var userName = "{{user-name}}";
var rawPassword = "{{password}}";
var securePassword = new SecureString();
foreach (var c in rawPassword)
{
securePassword.AppendChar(c);
}
var credentials = new SharePointOnlineCredentials(userName, securePassword);
var clientContext = new ClientContext(siteUrl)
{
Credentials = credentials
};
var webTemplates = clientContext.Web.GetAvailableWebTemplates(1041, true);
clientContext.Load(webTemplates);
clientContext.ExecuteQuery();
var webTemplate = webTemplates.FirstOrDefault(x => x.Name == "STS#0");
Console.ReadLine();
}
}
結果として Path プロパティの値が null になります。
CSOM では、オブジェクト自身の場所を特定するために、オブジェクトが Load された後、識別情報を Path プロパティに保持します。たとえばリスト アイテムの場合、以下のような値が格納されます。
5e66049e-800e-4000-b805-a573a858fe86|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:217cc400-7454-40e2-8f0d-546625dfb9fb:web:564072f0-9feb-48d6-b7bc-f77e17623c87:list:00077cba-a4e8-460f-a2b3-3a96a2da523f:item:1,1
site:217c...
や web:5640...
となっている部分が、それぞれの親オブジェクトの ID です。Load メソッドを呼び出す際は常にこの値を参照します。そのため、WebTemplate を Load しようとすると常に例外が発生します。
Discussion