Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm retrieving different custom and default user properties from the my sites profile in a webpart.

The Problem is, if i'm trying to retrieve profile information which hasn't been set yet the webpart throws a System.NullReferenceException.

How can i check if the property is set to work around that problem?

share|improve this question
1  
please post some code, or we cant help you. –  Anders Rask Aug 23 '11 at 14:08
    
Here is the code where the exception is thrown: result = u[property].Value.ToString(); –  Peter Aug 30 '11 at 8:52

1 Answer 1

up vote 1 down vote accepted

if (properties["MyProperty"] != null) { ... ?

share|improve this answer
    
Sorry, doesn't work. Debugger jumps not in the if-clause.. don't know why :/ Looks like this:if (u[property] == null) { result = String.Empty; } else { result = u[property].Value.ToString(); } –  Peter Sep 13 '11 at 10:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.