Code to Create a New Profile
This section shows how to create a new profile. Two new profiles will be created, oUser1, a UserObject profile, and oAddress1, an Address profile.
Note
- If the CreateProfile method fails on an aggregated profile (one that has multiple data sources), the DeleteProfile method must be called to clean up any entries in the data stores. In this case, the DeleteProfile method will produce an error that should be ignored.
If not already connected, create a ProfileService object, oProfileService, and establish a connection to the Profile Store. For information about connecting to the Profile Store, see Code to Connect to the Profile Store.
Create two new empty profiles (ProfileObject objects) using the ProfileService object, oProfileService, created in Step 1. For information about the valid profile schema types (specified as the second parameter of the CreateProfile method) and their associated properties, see Profile Schema. The primary key for the Address profile is a globally unique identifier (GUID), obtained through a GenID object.
Dim oUser1, oAddress1 Set oUser1 = oProfileService.CreateProfile("JoeUser@microsoft.com", _ "UserObject") If err.number <> 0 Then oProfileService.DeleteProfile "JoeUser@microsoft.com", "UserObject" EndIf Dim oGenID, sGUID Set oGenID = Server.CreateObject("Commerce.GenID") sGUID = oGenID.GenGUIDString Set oAddress1 = oProfileService.CreateProfile(sGUID, "Address")
Populate the desired properties of the profiles. The logon_name property of the oUser1 profile is already specified (as the first parameter of the CreateProfile method). Note that ProfileObject objects support extended dot notation and smart navigation. For more information, see ProfileObject Object.
oUser1.GeneralInfo.first_name = "Joe" oUser1.GeneralInfo.last_name = "User" oAddress1.GeneralInfo.region_code = "WA" oAddress1.GeneralInfo.country_code = "US"
Save the profiles to the underlying Profile Store.
oUser1.Update oAddress1.Update
Release the objects.
Set oUser1 = Nothing Set oAddress1 = Nothing
Copyright © 2005 Microsoft Corporation.
All rights reserved.