Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查PeopleManager上是否存在personProperty_C#_Sharepoint_Csom - Fatal编程技术网

C# 检查PeopleManager上是否存在personProperty

C# 检查PeopleManager上是否存在personProperty,c#,sharepoint,csom,C#,Sharepoint,Csom,我有以下代码从广告中的用户检索数据: PeopleManager peopleManager = new PeopleManager(clientContext); PersonProperties personProperties = peopleManager.GetPropertiesFor(loginName); clientContext.Load(personProperties); clientContext.Load(personProperties, p => p.Acc

我有以下代码从广告中的用户检索数据:

PeopleManager peopleManager = new PeopleManager(clientContext);
PersonProperties personProperties = peopleManager.GetPropertiesFor(loginName);
clientContext.Load(personProperties);
clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
clientContext.ExecuteQuery();

var personalUrl=personProperties.PersonalUrl;
最后一行对某些用户(而不是所有用户)抛出错误:

Microsoft.SharePoint.Client.ServerObjectNullReferenceException:对象引用未设置为服务器上对象的实例。该对象与方法GetPropertiesFor关联。 位于Microsoft.SharePoint.Client.ClientObject.CheckUninitializedProperty(字符串propName) 在Microsoft.SharePoint.Client.UserProfiles.PersonProperties.get_PersonalUrl()上

简单地说:在尝试检索值之前,是否有方法检查该属性是否已设置


或者,
try..catch
是解决此问题的唯一(丑陋)方法吗?

PersonProperties对象具有IsPropertyAvailable方法,该方法根据是否设置属性返回布尔值

因此,最后一行需要替换为:

string personalUrl=personProperties.IsPropertyAvailable("PersonalUrl")?personProperties.PersonalUrl:null;

如果最后一行抛出了一个错误,那么personProperties不是空的吗?不是。。