【问题标题】:empty sharepoint user profile property throw an exception空的 sharepoint 用户配置文件属性引发异常
【发布时间】:2010-04-14 23:10:39
【问题描述】:

我有一个用户配置文件属性。用户没有为该属性分配任何值。如果我使用下面的代码。它正在引发异常“对象引用未设置为对象的实例”

userprof["OptOut"].ToString()

我尝试了所有类型 喜欢

if (userprof["OptOut"] != null)
          OR
if(userprof["OptOut"].Value != null)

对我来说没有任何结果。

这里 userProf 对象是有价值的。 userprof["OptOut"].Value 为空

如何处理?

【问题讨论】:

    标签: sharepoint


    【解决方案1】:

    你必须像这样检查它:

    if (userprof["OptOut"][0] != null)
    

    我用这个方法:

        private string GetPropertyValue(UserProfile userProfile, string propertyName)
        {
            try
            {
                if (userProfile[propertyName][0] == null)
                    {
                     //code like this:
                     //return "'" + propertyName + "' value is null";
                    }
    
                return userProfile[propertyName].ToString();
            }
            catch (Exception ex)
            {
             //code like this:
             //return string.Format("Error with '{0}' UP-property: {1}", propertyName, ex.Message);
            }
            return "-";
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多