I have been working quite on some sharepoint stuff and faced a scenario of ensuring whether a particular user is valid or not either with the sam account name or with the complete name.
So I have used the below statement in my code and then ensured the user is valid or not.It ensures that the user is present in Active Directory.
SPUser assignedUser = web.EnsureUser("
Using this we would be able to update the columns like "Created By", "Assigned To" and so on where they are either people picker columns or people columns.
Just what you must do is create an SPUser object and then ensure it using the web (where web is the object for SPWeb) then assign this to the column of the list which is intended for.
Note: I even have faced the issue where the EnsureUser is not working with the web, so seriously what i have done is i have taken a new web object with the spSiteColl.RootWeb() then my problem got resolved.
Ref Code:
- SPSite site = new SPSite();
- SPWeb web = site.RootWeb();
- SPUser assignedUser = web.EnsureUser("
"); - web.Dispose();
- site.Dispose();