Display custom fields values


I have been learning about Campaign Monitor's API feature to manage our Campaign Monitor's subscribers list through forms hosted on our site.

I have created a custom field called preferences and would like to display the value(s) of that field using ASP.NET. 

Here's the scenario.  When a user logs in to view his or her profile on our site, I would like to display all value(s) of the "preferences" custom field for a particular user in the contact by email portion to show the user what type of emails he is currently receiving.

I have managed to display the number of "preferences" the user has selected with the following code:

SubscriberDetail subscriberDetail = new SubscriberDetail();
Subscriber subscriber = new Subscriber("ID");

subscriberDetail = subscriber.Get(txtEmail.Text);
lblMessage.Text = subscriberDetail.CustomFields.Count.ToString()

If someone can show me an ASP.NET example how to display what those preferences are, I will gladly appreciate it.


roshodgekiss roshodgekiss, 4 years ago

Hi Earth Day Canada, sorry for the wait here - I'm going to ask our fine dev folks to lend a hand here. Stay tuned, we won't be long!

Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
terryt terryt, 4 years ago

Hi Earth Day Canada,

So, there are a few different ways to display the custom fields in ASP.NET, all of which will require you to iterate through the list of custom fields.  Have a look at Getting a subscribers's details to see how the data is structured.  To iterate through those custom fields you'll want to do something like this:

foreach (var customField in subscriberDetail.CustomFields.Where(cf => cf.Key == "preferences"))
    // print out the selected item or do some type of update, where the selected
    // custom field is just customField.Value

Hopefully this points you in the right direction.

Terry Tice

Terry Tice
Campaign Monitor
Earth Day Canada, 4 years ago

Thanks Terryt and roshodgekiss.

The code you provided gave me the result I was after.  Come to think of it...is there a way to list all the preferences values?

This will allow me to display the full custom value "preference" list from Campaign Monitor (as a checkbox list) and using the above example as the inner loop, I can determine whether to tick off the ones the user is currently receiving while showing other types of email we offer the user may be interested receiving.


terryt terryt, 4 years ago


You'll want to have a look at the createsend_dotnet.List class.  Inside that class you'll be able to get the custom fields for the list.  Here's a sample:

createsend_dotnet.List list = new createsend_dotnet.List("<your list ID here>");
foreach (var customField in list.CustomFields())
    string fieldName = customField.FieldName;
    foreach (string option in customField.FieldOptions)

Always worth having a look at the API documentation as our wrappers mimic it very closely.  So, in this instance, you want to get all the custom fields for a list.  Head over to the Lists documentation and over on the right is a section to List Custom Fields.  So, our wrapper has a "List" object with a method called "CustomFields".

Hopefully this points you in the right direction!

Terry Tice

Terry Tice
Campaign Monitor

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free