User Profile fields in FBA Pack

Mar 26, 2012 at 3:01 AM
Edited Mar 26, 2012 at 3:02 AM

Is it possible to add fields to the user profile in sharepoint, (eg. address, phone number). If this is possible, can you please explain how this is done.

Does your request membership web part automatically update with the additional fields or will this need to be modified manually.

Coordinator
Mar 26, 2012 at 1:12 PM

Sorry, but currently there's no built in way to set any additional fields. I've done this for other clients by creating a user profile web part that writes to custom fields, but the fields were hard coded.

Mar 26, 2012 at 1:14 PM

Is it possible to get a copy of the web part that does this?


On 27/03/2012, at 12:12 AM, "ccoulson" <notifications@codeplex.com> wrote:

From: ccoulson

Sorry, but currently there's no built in way to set any additional fields. I've done this for other clients by creating a user profile web part that writes to custom fields, but the fields were hard coded.

Coordinator
Mar 26, 2012 at 1:23 PM
Edited Mar 26, 2012 at 1:25 PM

Sorry, it's private code for a client. Here's essentially the code it uses to add/read/write to the user's profile though:

 

//Create additional fields on Profile list (one time process - usually you put this in your feature event receiver so it's called when the feature is activated

SPSite site = properties.Feature.Parent as SPSite;

SPList list = site.RootWeb.SiteUserInfoList;

SPField field;

if (!list.Fields.ContainsField("FieldName"))

{

field = list.Fields.CreateNewField(SPFieldType.Boolean.ToString(), "FieldName"); //You can change the field data type here as well

list.Fields.Add(field);

list.Update();

}
                                                

//Save values to user profile list

SPUser user = web.CurrentUser;
SPListItem userItem = web.SiteUserInfoList.GetItemById(user.ID);
userItem["FieldName"] = FieldValue;
userItem.Update();                                      
                                                                                                                                                            

//Read values from user profile list

SPUser user = web.CurrentUser;
SPListItem userItem = web.SiteUserInfoList.GetItemById(user.ID);
textcontrol.Text = (userItem["FieldName"] as string);
Feb 2, 2015 at 2:34 PM
Hello ccoulson,

Thanks for providing these bits of code, however I'm still a bit stuck with this last part of the requirement to add 3 additional fields to the FBA user request process.

I have managed to update the appropriate form to include the new fields but I now need these new field values to be stored somewhere (in SQL) and to then be called/ viewed in either the SP User profile List, Membership Request List or User management settings.

As a new SharePoint developer I'm not that familiar with the with the SharePoint OM at the moment. Could I kindly ask for a summary/run down of the steps I need to take to achieve this?
I have attempted to add the first bit of code to the FBA Management feature part of the solution but with the Save values and Read values, Web is not within the context of the FBA Management Event Receiver code?

Should the save and read value code be compiled within the FBA Event receicer?

Finally, Is it possible to add the 3 new (simple text) fields to the Membership request list/view? I have tried to do this by updating the Schema but unsuccessfully at the moment. Your help on this last bit of my requirement would be great.

If its not possible how do you suggest I take this forward?
Coordinator
Feb 2, 2015 at 7:16 PM
Right, on top of adding the fields to the form, you also have to add the logic to handle the fields. There's A LOT of places where this needs to be done. What I do is just search the code for 'email' - which will find all the places the email field is handled, and then duplicate that logic for the new fields.

Same goes for adding the fields to the membership request list/view. Just edit the schema. Find the email field and copy it for your new fields, just changing the names and generating new guid's.

For the event receiver, you just have to change GetMembershipRequest to additionally handle the new fields (Again, just searching for 'email', and adding the new logic in those locations).

For storing the additional fields, I usually just store them directly in the user's SharePoint profile (which is what the above code does) - so no need to store them in SQL.
Feb 3, 2015 at 7:40 AM
Thank you ccoulson,

This is exactly what I've started to do, so this is good confirmation for me.

In terms of using the code above, I will again attempt to use the save and read values code and apply this to the appropriate area where web context is in scope.

I'll keep you posted on my progress...so far so good and thank you once again.
Feb 3, 2015 at 3:37 PM
Hello Ccoulson,

Unfortunately I'm unable to extend the MembershipRequest class to include my additional fields from the SiteUserInfoList....Sorry to be a pain but are you able to advise how I do this. Is it in fact possible?

Do I have to create a separate custom Membership class to include these additional fields?.

This is the last piece to the puzzle but I'm totally at a loss at the moment.

I'm also unable to add the code above to the FBA Management Event Receiver code - in particular the Save and Read Values sections!? as fieldValue and textcontrol.text are not within the current context (I was unable to establish the appropriate references for these members/properties.


Public static MembershipRequest GetMembershipRequest(MembershipUser user, SPWeb)
  • I know the above inherits from the Membership Class which is limited to specific User login fields etc and with SPWeb allows for the UserInfoList fileds properties to be exposed, but as I've been unable to add the custom fields to this list I'm getting nowhere (unless I have this totally wrong).
I have seen other solutions but would like your advice/guidance on this.

Thank you ever-so-much for your help.
Coordinator
Feb 4, 2015 at 3:07 PM
I just update the existing membershiprequest class and add the properties directly to it.

I don't add the fields to the membership database, so I don't add them to the membership class. I update it where the email address is stored on the sharepoint profile (spuser).