Welcome to tankete.com Sign in | Join | Help

José Lema

Inside the Community Server development team

Shared Posts


Badges



  • www.flickr.com
    This is a Flickr badge showing public photos from tankete. Make your own badge here.
CS Spotlight: Extended User Data

Introduction 

For this week's spotlight, I figured I'd talk about another often overlooked feature that exists in Community Server, ExtendedUserData. This small feature grew out of numerous client requests to include additional profile information during both registration and profile editing while not touching core code. While it's not the end-all solution it's quite simple to setup and meets the demands of the basic scenarios. You could add controls to the correct skins, configure the fields in communityserver.config, and then the magic would happen. Whenever a user registers, their additional input would be captured and stored in ExtendedAttributes for display on profile editing. Using additional non-evasive techniques, this data can be surfaced on most any additional skin.

At this time, the skins that participate in the feature are Themes\default\Skins\Skin-CreateUser.ascx, Themes\default\Skins\Skin-EditProfile.ascx, and ControlPanel\Membership\UserEdit.aspx. Since these skins are not read-only, there is some needed code-behind that exists for capturing the data. For any other skin files, if you need to display this data, you would just pull it out of the user object.

Example

Assume your site is planning on contacting folks via postal mail. (I know, "That's so 80's!", but work with me here). You've decided to request the following pieces of information:

  • Address Line 1
  • Address Line 2
  • City
  • State
  • Zip

So, the first step would be to open up the registration skin (Themes\default\Skins\Skin-CreateUser.ascx) and add markup and server controls to capture the data. For example, in order to add input for the first address line, you could add the following:

...
<tr>
    <td align="right">
        Address Line 1
    </td>
    <td align="left">
        <div class="CommonFormField">
            <asp:TextBox id="addressLine1" runat="server" />
        </div>
    </td>
</tr>
...

Once you're done adding the controls to the skins, you need to open communityserver.config. While the location doesn't matter, I recommend adding the following near the bottom of the file since it's extra.

...
<ExtendedUserData>
    <add name="addressLine1" />
    <add name="addressLine2" />
    <add name="city" />
    <add name="state" />
    <add name="zip" />
</ExtendedUserData>
....

That's really all you need to do! CS will loop thru the list of extended user data and bind existing data to controls it finds. This means the server controls must be named the same as the configuration information. At this time, you can use any controls that derive from TextBox, CheckBox, and ListControl.

Next Steps

Now, some folks will want to display this data on the user's public profile page. Since that would be a read-only scenario, there's no core code needed to support it. You could just open up the user profile skin (Themes\default\Skins\Skin-UserProfile.ascx) and add the following:

<%= CSContext.Current.User.GetExtendedAttribute("addressLine1") %>

But doing so would display the logged on user's value for the data. Since you'll most likely want to view information for other users, especially on their profile, I recommend you add the following to your user profile skin:

<script language="cs" runat="server">
User GetUserToView()
{
    User user = null;
    CSContext csContext = CSContext.Current;
    int userID = csContext.UserID;

    if (userID <= 0)
    {
        string username = Context.Request.QueryString["UserName"];
        if (username == string.Empty)
            throw new CSException(CSExceptionType.UserNotFound);
        else
            user = Users.GetUser(0, username, false, true);
    }
    else
    {
        user = Users.GetUser(csContext.UserID, false, true);
    }

    return user;
}
</script>

Then, somewhere within your markup, you could include the following:

<%= GetUserToView().GetExtendedAttribute("addressLine1") %>

As with many other configuration based updates, you'll need to "touch" the web.config file in order to flush the existing configuration and reload the updated changes.

Summary

Community Server offers many ways to extend the platform. Today we've peeked at yet another non-invasive method to extend a user's profile information. For a peek at this type of implementation in the wild, be sure to check out The Hive and specifically the registration form.

Posted: Thursday, June 29, 2006 6:41 PM by Jose
Filed under: ,

Comments

Simone said:

Does this apply also to blog extended options?

or just to user data?

# June 30, 2006 4:01 AM

Jose said:

Simone - Unfortunately this is only for user-related information.

# June 30, 2006 5:19 AM

Simone said:

Too bad it works only with users.

I wanted to add extended attribute to users blog, but now I'm limited only to those things that can be detected automatically from the text or from the user logged on. :-(

# June 30, 2006 10:33 AM

Jason Haley said:

# June 30, 2006 11:03 AM

Jason Haley said:

# June 30, 2006 11:04 AM

Dave Burke said:

Simone asked the same question I was going to ask.

Now I know where to relaunch my EA investigations!

Thanks so much for writing this up.  Very clearly written, too.

# June 30, 2006 11:53 AM

Community Server Daily News said:

news of the daya grab bag for what&amp;#39;s happening in Community ServerKen Robertson reflects on his two

# June 30, 2006 2:53 PM

J-O Eriksson said:

Would it be possible, without touching the source code, to create a field in the registration form that maps to an existing user property?

For example, let's say I want the user to choose wether to recieve notifications or not when they register.

# July 7, 2006 8:22 PM

pablosan said:

First off, nice article!  Well-written and easy to follow - and exactly what I was looking for.  However after following the simple-appearing steps, double and triple-checking my spelling, etc. the data doesn't seem to be getting saved.

in the skin files:

<asp:Textbox ID="AgeGroup" runat="server" MaxLength="20" />

[<%= CSContext.Current.User.GetExtendedAttribute("AgeGroup") %>]

in the communityserver.config:

<ExtendedUserData>

    <add name = "AgeGroup" />

</ExtendedUserData>

in the database/profile:

nothing!  

Nothing seems to get stored or is retrieved from the GetExtendedAttribute call.  I've restarted the CS application in IIS, logged in/out, updated the user profile numerous times, tried textboxes and dropdown lists - nada.  Are there any special requirements or additional settings needed to get this to work?  TIA!

# July 19, 2006 5:11 PM

Jose said:

Hi pablosan,

I registered on your site (trackback url + "/cs") to see what you were talking about and I noticed the Age Group drop down. I would first get it to work on a simple textbox before trying the drop down. But it sounds like that didn't work either. You shouldn't need to do anything with .GetExtendedAttribute(xxx) since the control name matches and should be bound automatically. Maybe the <ExtendedUserData> element isn't properly nested in the main <CommunityServer> element? Feel free to email me your cs.config file and your skin file and I'll take a peek. I'm at jlema AT telligent DOT com.

# July 20, 2006 3:34 AM

Community Server Daily News said:

This is a compilation of all Forum FAQ content on communityserver.org to serve as a timestamp of where

# July 24, 2006 5:42 PM

dimitrisv said:

Great work Jose!

Thank you.

Can you please help us further by telling us how can we update/save these extended attributes from community server?

# August 17, 2006 8:01 AM

Jose said:

Hi dimitrisv,

In order to persist extended attributes, you'll need to first set it, then update the containing object. So, if you're adding extendedattributes to the User object, you would first do aUser.SetExtendedAttribute("name", "Jose") and then Users.Update(aUser). Hope that answers the question.

# August 17, 2006 12:25 PM

Jacob Portnoy said:

Is this also possible to implement with files? For example, if I want to add the field "abstract" to files uploaded, could that be done through extended attributes? Please advise via jportnoy [at] cfinst [dot] org. Thank you in advance.

# August 18, 2006 1:22 PM

gkonto said:

Providing the fact that many applications have developed and integrated with CS using asp.net membership and memberrole.dll from older versions of Community Server, which solution is preferred for existing extended attributes, during migration phase to CS 2.1? Keep using the extended attributes of asp.net membership (core code) or migrate to ExtendedUserData?

# August 19, 2006 12:23 PM

Jose said:

Hi Jacob,

At this time, the post editors are not built with any awareness for this type of behavior. So while you could write a CSModule to add information to a Files extended attributes, there's no way (without tweaking the core) to get that information from on screen controls. In a future version of CS you should be able to extend the post editor and allow for the addition of new fields.

# August 21, 2006 6:50 PM

Jose said:

Hi gkonto,

It all depends on the scenario you're looking to enable. If you want a no-code approach to additional user-registration fields, then I would definitely recommend ExtendedUserData.

# August 21, 2006 6:53 PM

LacOniC said:

Is it possible to search a user with extended user data? As i understood it's not possbile because all these datas are in same string. If i want to add data to search, must i use another way?

# September 8, 2006 8:36 AM

Jose said:

Hi LacOniC,

You are correct that all extended attributes are stored in a single string. As a result, searching is not as easy. You could cobble something together using a function like FetchExtendedAttribute (http://code.communityserver.org/?path=CS+Tree%5cSampleCode%5cSQL%5cFetchExtendendAttributeValue.sql)

Hope that helps,

JL

# September 8, 2006 11:49 AM

Community Server Daily News said:

news of the day a grab bag for what's happening in Community Server It's getting real. The Telligent

# September 14, 2006 3:57 PM

Community Server Daily News said:

news of the day a grab bag for what's happening in Community Server I don't know about you, but I learn

# September 27, 2006 3:58 PM

Simon Allport said:

Hi, can anyone tell me where the data is kept within the database?

# November 8, 2006 6:23 AM

Jose said:

Hi Simon,

This data would be stored in the PropertyNames/PropertyValues columns of the cs_UserProfile table.

# November 8, 2006 11:05 AM

Daily News Faq List said:

Mark Merrick writes an extensive post with ample source code on how his Vanguard University added new

# November 22, 2006 11:15 AM

Daily News Faq List said:

CarKnee provides a couple good links on working with User Profile Extended Attributes for a request to

# November 22, 2006 11:18 AM

Daily News Faq List said:

I&#39;ve been looking forward to this post! Jose Lema writes about the ExtendedUserData feature in Community

# November 22, 2006 11:50 AM

FAQs - Communityserver.Org said:

FAQ posts contain multiple subject items appropriate to this forum, and will evolve over time with new

# January 9, 2007 11:39 PM

Community Server Bits said:

Mark Merrick writes an extensive post with ample source code on how his Vanguard University added new

# March 12, 2007 11:20 AM

Community Server Bits said:

CarKnee provides a couple good links on working with User Profile Extended Attributes for a request to

# March 12, 2007 11:24 AM

Community Server Bits said:

I&#39;ve been looking forward to this post! Jose Lema writes about the ExtendedUserData feature in Community

# March 12, 2007 12:01 PM

andrew @ grr, argh! said:

It's taking me quite a while to get used to the programming behind this site. I tried setting up some

# June 21, 2007 8:36 AM
New Comments to this post are disabled