SPFieldUserValue field = new SPFieldUserValue(web, item["AssignedTo"].ToString()); // Test for a user or group value (null indicates a group) if (field.User != null) { //user } else { //group }
Subscribe to:
Post Comments (Atom)
C#, .Net, MVC, jQuery, JavaScript, HTML, CSS, Umbraco, Phonegap / Cordova, Xamarin, iPhone, iOS, Swift, Android, Windows, apps, websites, Full Stack, ecommerce, Facebook, responsive, front-end. Freelance developer, programmer for web and mobile in Bristol, UK.
A user who has been removed from a site will also come back with field.User as null, sending you into the group code.
ReplyDeleteAnd another gotcha that made things worse, web.Groups.GetByID doesn't check that a group exists before trying to get the group and errors out.
As far as I can tell, the best option is to use a method to check if the group exists before you try to get it. And if it doesn't assume it is a removed user or group.