Question

How to convert this display name to SPUser type.

My input is Sivakumar, Piratheban (ext)(domain\user)

Was it helpful?

Solution

There is no direct convertion but you can use a regular expression to pull out the login name and then call EnsureUser on that.

var login = Regex.Match(input, @"\((?<login>[^\(\\]+\\[^\(\\]+)\)$", RegexOptions.ExplicitCapture).Groups["login"].Value;
var user = web.EnsureUser(login);

OTHER TIPS

You could extract login name from input string using String.Split Method and then initialize a user:

var loginName = input.Split('(', ')')[3];
var user = web.EnsureUser(loginName);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top