About      |       Articles      |      Services      |      Software      |      Contact

Latest Free SharePoint Software

ARB Security Solutions regularly releases free SharePoint software, including WebParts, Client Applications, Framework Extensions, and other Miscellaneous Components.
The most recent freeware is:

Title: Simple SharePoint Rollup WebPart
Date Published: 10/22/2009

Previous Two Free WebPart Releases:

SecureCenter For SharePoint

By SharePoint security integrators, for SharePoint security integrators.

SharePoint Security Assurance Program™

For externally facing SharePoint deployments, security is an acutely important deployment concern. Learn how through daily security scanning, you can ensure external business users and partners that they can collaborate in confidence!

Security Assurance WebPart:



Return Current User SharePoint MySite URL

Sometimes in code you want to include a link to the users MySite url in a string. This is helpful when doing things like writing out sets of user names in a WebPart, and want to include a link to more information regarding the user. You can accomplish this pretty easy by tapping into the SharePoint Object Model, and is a nice enhancement that adds a little bit of elegancy to a WebPart.

The first thing that you have to do is build a small test in order to determine whether the user has been authenticated to SharePoint. This can be done using the IsAuthenticated property against the user identity within the current site context, nothing real fancy here. This will be passed into the _curUser global variable (a private string) in the WebPart class.

C#:
  1. SPWeb web = SPControl.GetContextWeb(this.Context);
  2.  
  3. if (this.Context.User.Identity.IsAuthenticated)
  4. {
  5. this._curUser = web.CurrentUser.LoginName;
  6. }

Afterwords, you can loop through all the site collection using the sites property of the SPWebApplication class with a foreach loop. Following, using the SPWeb.WebTemplate property will get the name of the site definition that was used to create a relevant site. Since the SharePoint site definitions are explicitly named within the SharePoint 12 hive, you can test for the folder name of the MySite site definition by checking whether the return is equivalent to the string "SPSPERS" (the name of the MySite site definition). The if statement is extended in order to pass the current users login information to properly match it to the right user. Following, you can return the url of the user MySite by using the SPWeb.Url property.

C#:
  1. foreach (SPSite site in webapp.Sites)
  2. {
  3. if (site.RootWeb.WebTemplate.ToUpper().StartsWith("SPSPERS") && site.Owner.LoginName.Equals(this._curUser))
  4. {
  5. return site.RootWeb.Url;
  6. }
  7. }

That's all! Now you have a reference to the current user's my site. You can decorate this within your rendered WebPart HTML stream by doing a similiar site definition test to do things like parse out an image to make your Webpart property by doing (web.WebTemplate.ToUpper().StartsWith("SPSPERS")).

  • Share/Bookmark

4 Comments »

  1. A nice quick and easy way to return the current user’s name. Exactly what I was looking for, thanks!

    Comment by Jason — September 23, 2008 @ 7:24 pm

  2. ServerContext context = ServerContext.GetContext(site);

    UserProfileManager profileManager = new UserProfileManager(context);
    UserProfile profile = profileManager.GetUserProfile(HttpContext.Current.User.Identity.Name);
    string personUrl = profile.PersonalSite.Url;

    Comment by zsbfree — January 12, 2009 @ 12:06 am

  3. Well done, the context method is much cleaner.

    Comment by Adam Buenz — January 12, 2009 @ 3:16 pm

  4. Nice !!!!!!!!

    get sharepoint user and group, it is simple.

    Try this too,
    Get Current SharePoint user

    Comment by sara — October 1, 2009 @ 9:44 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment