Views: 6215
Number of votes: 0
Average rating:

Migrating PersonalizedData – the quick and dirty way

If the site you are migrating is using the PersonalizedData class to store non-standard values for the users, you will soon discover that the Migration Tool does not (yet?) migrate this data. You have to do it yourself, and here is a quick and dirty way to do it.

Description

Linked from this post are two aspx pages.ExportUserProfileDataFromEPiServer4.aspx will export data from PersonalizedData objects on the CMS 4.62 site and store it in an XML file. ImportUserProfileDataToEPiServer5.aspx will import the data to the EPiServerProfile objects on the CMS 5 site.

Edit the files to include the properties you need and to use a file path where the webserver user has sufficient access rights.

Example for ExportUserProfileDataFromEPiServer4.aspx:

   1: private Dictionary<string, string> GetDataForProfile(PersonalizedData data)
   2:     {
   3:         Dictionary<string, string> values = new Dictionary<string, string>();
   4:         //
   5:         // TODO: Add code here to export values
   6:         //
   7:         // Example:
   8:         // // "MyKey" will be the key to find the value when importing
   9:         // values.Add("MyKey", data.Description);
  10:  
  11:         values.Add("Description", data.Description);
  12:         values.Add("NewsletterSubscriptions", data["NewsletterSubscriptions"] as string);
  13:  
  14:         return values;
  15:     }
  16:  
  17:     private string FilePath
  18:     {
  19:         get
  20:         {
  21:             //
  22:             // TODO: Set output filename here
  23:             //
  24:             string filePath = @"C:\Temp\UserData\UserData.xml";
  25:             return filePath;
  26:         }
  27:     }

Example for ImportUserProfileDataToEPiServer5.aspx:

   1: private void SetDataForProfile(EPiServerProfile profile, Dictionary<string, string> data)
   2: {
   3:     //
   4:     // TODO: Add code here to import values
   5:     //
   6:     // Example: 
   7:     // // "Key" is the string used to store the value when exported
   8:     // string value = data["Key"];
   9:     //
  10:     // // Add logic to import the value
  11:     // if (!String.IsNullOrEmpty(value))
  12:     // {
  13:     //     profile["ProfileProperty"] = value;
  14:     // }
  15:     string desc = data["Description"];
  16:     if (!String.IsNullOrEmpty(desc))
  17:     {
  18:         profile["NewsLetterDescription"] = desc;
  19:     }
  20:  
  21:     string sub = data["NewsletterSubscriptions"];
  22:     if (!String.IsNullOrEmpty(sub))
  23:     {
  24:         profile["NewsletterSubscriptions"] = sub;
  25:     }
  26: }
  27:  
  28: private string FilePath
  29: {
  30:     get
  31:     {
  32:         //
  33:         // TODO: Set input filename here
  34:         //
  35:         string filePath = @"C:\Temp\UserData\UserData.xml";
  36:         return filePath;
  37:     }
  38: }

You also have to add your new properties to the profile/properties section of the CMS 5 site web.config, if you haven’t already done so.

Then just put the files somewhere in your sites, navigate to ExportUserProfileDataFromEPiServer4.aspx and run the export and then navigate to ImportUserProfileDataToEPiServer5.aspx and run the import. Done!

Download

Download MigratePersonalizedData.zip here.

Feb 18, 2009

Guest
(By Guest, 9/21/2010 12:32:23 PM)

Excellent, Magnus. Thanks for the heads-up.
/ Mårten Berg

Magnus Rahl
(By Magnus Rahl, 9/21/2010 12:32:23 PM)

Apparently the latest version of the migration tool can handle this conversion, it is even possible to hook event handlers in to process the information before it is written to the personalization provider.

Please login to comment.