The Problem
I recently had to develop an Event Receiver that would require reading off the SPUser object of the item. What I found is that, at times when the exact name of the user is entered (and you click OK on the NewForm.aspx page without clicking the check name button), the SPFieldUserValue will return
–1;#domain\username
rather than
This is a problem when you try to access the SPFieldUserValue.User (SPUser type) property and it returns null.
The Solution
The solution was to get the SPFieldUserValue as a string, and then use the username to then try and resolve for the SPUser object. My rough cut out code is attached – quickly modified for this example. (*Use at your own risk. Is also why I don’t usually post code on my blog!)
No comments:
Post a Comment