SharePoint 2010 - MySite Redirection

When user's click a user's name in a document library, etc, a file userdisp.aspx controls where the user is directed. Assuming you want to have all user links bring users to My Sites, you can start off creating the user control, by the following code on and then in the RedirectIfNecessary(SPListItem user) you can utilize the following code.

if (Request.QueryString["id"] != null)
    SPSite _site = SPContext.Current.Site;
    SPServiceContext _serviceContext = SPServiceContext.GetContext(_site);
    UserProfileManager _userProfileManager = 
        new UserProfileManager(_serviceContext);
    string _mySiteUrl = _userProfileManager.MySiteHostUrl;
    string _profileUrl = string.Empty;
    int userID = 0;
    if (int.TryParse(Request.QueryString["id"].ToString(), out userID))
        SPUser profileUser = SPContext.Current.Web.SiteUsers.GetByID(userID);
        if (_userProfileManager.UserExists(profileUser.LoginName))
            UserProfile _userProfile = 
            _profileUrl = _userProfile.PublicUrl.AbsoluteUri;
            _profileUrl = String.Format("{0}Person.aspx?accountname={1}", 
                _mySiteUrl, profileUser.LoginName);
        SPUtility.Redirect(_profileUrl, SPRedirectFlags.Static, this.Context);


Popular posts from this blog

C# - ListView Item Spacing (Padding)

C# - Performance Counters

IIS / ASP.NET - Disabling Compatibility Mode/View (Internet Explorer)