Discussing the nuts and bolts of software development

Friday, September 12, 2008


Bridge SharePoint - User Profiles and User Profile Properties (part 2 of 2)

As we have found out in part 1, SharePoint can manipulate data using the user profile management objects and can accept data from external sources. Using these two features apart we have two limited tools with limited usage, but using them together gives us a powerful, flexible and efficient method of storing and using data from any internal or external resource.

It’s time to see this solution to our problems in action.

Code example of getting/setting the profile property from a C# application

The concept is the same for any source of information (web services, web applications, etc.):
Get the user’s profile->Get the required profile property->Get/Set profile property value

Code example: (note that to access profile properties, this code must run with elevated privileges)

string value;

// Change the site address for different deployment environments
// Note: WIN2003STD is a place holder for your environment, usually your server name
SPSite site = new SPSite("http://WIN2003STD/");
SPWeb web = site.OpenWeb();

// Get the profile manager object for the site
UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(site));

// Use the username from the User Information Item to get the full profile of an user
UserProfile user_profile = profileManager.GetUserProfile(System.Web.HttpContext.Current.User.Identity.Name);

// Get the required profile property value from the profile
value = user_profile["MyProperty"].Value.ToString();

catch (Exception e)
return "Error getting user info: " + e.Message.ToString();

user_profile["MyProperty"].Value gets or sets the profile property value.

This is a very convenient way of using profile properties to store required information for each user. Properties can be set as read-only or not to appear in the user’s profile, which gives you even more control.

System.Web.HttpContext.Current.User.Identity.Name returns the username (the login username) and it is used in the code example above to get the profile of the currently logged-in user.

Tools You Never Knew You Had… (and what to do with them now that you’ve wised up!)

With this simple solution to getting/setting a user’s profile property value, endless opportunities are now at hand. This small code snippet helps developers control, validate and use values stored for each user, without corrupting the database or resorting to other more complex and error-prone solutions.
For those not needing to use an external application to get information from the users, a custom SharePoint web application can be developed and deployed on SharePoint. This way all the controls offered by ASP .NET or custom controls can be used to perform required operations on the data before it’s stored.

External applications running on the server can access this information the same way, so a bridge between SharePoint and applications like web sites, game servers, messaging apps, etc. can be easily created.

SharePoint Complications, As Usual

Watch out that the profile property might be set as read-only in SharePoint. Even if it’s the case however, the above code should still be able to access the profile because it’s running with elevated privileges. So if there is a situation in which the user is allowed to see the data but only modify it by using a service (like a web application or web service), this is a good way of doing it.

Another gotcha is that the code above can only be used on the SharePoint server machine. This is due to the framework that SharePoint uses. To get information or to change data from a network on internet location, a SharePoint custom web service or web application can come in handy. Other ways of passing information will work too, like server-client applications, as long as the part running the above code is on the SharePoint server machine.

So we now have a way to store data and manipulate it according to our needs. We can control it, we can validate it and most important of all, we decide how the user interacts with the data.

We’re now ready to start doing some serious SharePoint development!

Labels: , , , , ,

By the way, this information will be useful for college students. It will help you to learn more about PhD
We are here to provide top quality assignment help service. You can always get connected to us and we will make sure that you are able to complete your assignment in the most promising manner. The best part is you will be getting quality approved assignments at very reasonable pricing. Get connected to us now and avail the best of grades without any kind of hassle at all! Yes, you can reach out to our Economics assignment help writing experts anytime and get connected as per your convenience. They will respond back to your right away and make sure that all your queries and doubts are resolved.
This comment has been removed by the author.

نقل عفش من الدمام الى الرياض نقل عفش من الدمام الى الرياض
ارخص نقل عفش بمكة ارخص نقل عفش بمكة
نقل عفش من جدة الى الاردن نقل عفش من جدة الى الاردن
نقل عفش


Wow, awesome blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your
site is magnificent, let alone the content!

my web page :: 안마

Put more information on your website like this one, I really like these types of blogs.I am also wanted to write blog kindly guide me if my topic is seismic sensor manufacturers then what should I do first and how will I create new and unique content on this topic
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?