Let's say that we have the SPUser object of current user - how do I programmatically retrieve his mysite URL path, for example "mydomain:8080/personal/saltarski"?
Currently I do it through string manipulation:
var loginName = SPContext.Current.Web.CurrentUser.LoginName.Substring(SPContext.Current.Web.CurrentUser.LoginName.IndexOf('\\') + 1);
var hostName = SPContext.Current.Site.HostName;
SPSite site = new SPSite("http://" + hostName + ":8080/personal/" + loginName + "/")
This works for most cases, however I find that it breaks for some users like the System Admin, when his loginName resolves to 'system' but the actual path to the mysite contains his actual credentials' login name.
Is there a more elegant solution to what I am doing?