2010-04-14 2 views
1

사용자 프로필 속성이 있습니다. 사용자가 속성 값을 지정하지 않았습니다. 아래 코드를 사용하면. 그것은 예외를 thorwing있다빈 sharepoint 사용자 프로필 속성 예외가 발생합니다.

userprof["OptOut"].ToString() 

"개체 참조가 개체의 인스턴스로 설정되지 않았습니다"나는 아무것도 날 위해 일하지

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

같은 모든 유형을 을 시도했다.

여기 userProf 개체는 값을 가지고 있습니다. userprof [ "OptOut"]. 값이 null입니다.

처리 방법은 무엇입니까?

답변

0

이처럼 확인해야합니다

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 "-"; 
    } 
관련 문제