views:

256

answers:

4

I want to change an existing user's profile without having to create a new profile for the user. For example: I have a user name Usr1 and I want to change only his age, how do I do that?

A: 

If you have a look at this article, it explains how to do it...

Tim Almond
If this is a **web application** (think Asp.net MVC) then ProfileCommon is not auto-generated, and you have to revert to the non-typesafe ProfileBase
spender
+1  A: 

See this article for the full details. Be aware that in certain cases (see my comment to another answer), ProfileCommon is not generated.

In this case you need to revert to using ProfileBase:

ProfileBase profile = context.Profile;
DateTime dob= profile.GetPropertyValue("dob") as DateTime;
...
profile.SetPropertyValue("dob",dob);
spender
A: 

When you are in the page you have the ProfileCommon class available to you for accessing the profile. The profilecommon class is automatically generated by asp.net from you web.config profile settings during compilation of the web project.

In case you want to use the profile from app_code folder, you will have to use the profilebase class. Profilecommon that is available in the page also derives from this class.

Profilebase can be access like this

HttpContext.Profile or HttpContext.Current.Profile

To read a profile value you need to do the following

HttpContext.Profile.GetPropertyValue("propertyName");

To write a value to the profile you need to write

HttpContext.Profile.SetPropertyValue("propertyName", "propertyValue");
Bootcamp
A: 

If what you are trying to do is update another's user profile (say, you are an admin who types in a customer's username), you can use something like the following.

Dim p As ProfileCommon = Profile.GetProfile("Usr1")

p.TestValue1 = "New Value"
p.TestValue2 = "Another New Value"

p.Save()

Again, if you are using a web project instead of a web site, you will have to use p.SetPropertyValue() instead of the strong-typed property names.

NightOwl888