Hi,
I have just upgraded a client site from v4.1 to v6. The client site allows people to subscribe to their newsletters using a custom form submission. In Kentico v4.1 they were able to set custom fields to the 'Subscriber' class object using:
sb.DataClass.SetValue(<field name>,<value>);e.g. sb.DataClass.SetValue("SubscriberTitle", ddlTitle.SelectedItem.Text);
This is no longer possible in v6. The same (previosuly working) line of code now returns a compilation error:
CMS.DataEngine.AbstractInfo<CMS.Newsletter.Subscriber>.DataClass is inaccessible due to it's protection level.
So how do I assign custom fields to Subscriber objects in Kentico v6?
The previous working section of code is as follows:
// Get subscriber info
Subscriber sb = SubscriberProvider.GetSubscriberByEmail(txtEmail.Text,CMSContext.CurrentSiteID);
if (sb == null)
{
// Create subscriber
if (sb == null)
{
sb = new Subscriber();
}
// E-mail
sb.SubscriberEmail = txtEmail.Text.Trim();
sb.SubscriberFirstName = txtFirstName.Text;
sb.SubscriberLastName = txtLastName.Text;
// Full name
sb.SubscriberFullName = sb.SubscriberFirstName + " " + sb.SubscriberLastName;
//TODO assign custom fields here
//sb.DataClass.SetValue(<field name>,<value>);
sb.DataClass.SetValue("SubscriberTitle", ddlTitle.SelectedItem.Text);
sb.DataClass.SetValue("SubscriberState",ddlState.SelectedItem.Text);
sb.DataClass.SetValue("SubscriberNewsletterType", ddlType.SelectedItem.Text);
// Create guid
sb.SubscriberGUID = Guid.NewGuid();
// Site
sb.SubscriberSiteID = CMSContext.CurrentSite.SiteID;
// Save subscriber info
SubscriberProvider.SetSubscriber(sb);
}
// Return subscriber info object
return sb;