The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Checking if a Contact in a Contact List in C#

Occasional Contributor

Checking if a Contact in a Contact List in C#

How to I check to see if a contact is in a contact list?  I'm looking at contact.Lists.Exists where contact is my Contact, but having trouble in figuring out to use the right syntax.  I've tried:


if (contact.Lists.Exists) 


  // Do Something



but know this is not correct.  What is the correct syntax?  Thanks.

Occasional Contributor

Re: Checking if a Contact in a Contact List in C#

Another way I'm looking at is by getting the contacts from a list using getcontactsfromlist.  Can I use Results.Contains to check if a users email address is in the list?  If so, what is the correct syntax?  What I have so far is:



<Contact> contacts = cc.GetContactsFromList("22", DateTime.Now.AddMonths(-1));


I know it will then begin with contacts.Results.Contains.  What do I put for the item?



Re: Checking if a Contact in a Contact List in C#

If you're looking for a specific contacts information, it's likely easier to just search for that email address using our search feature.  You can find more information on that on this page in the documentation:


In the .Net wrapper, you would use the GetContacts() method and provide an optional email address to search for.  This will let you know if the Contact exists and get you information on said Contact.

Dave Berard
Senior Product Manager, Constant Contact
Regular Advisor

Re: Checking if a Contact in a Contact List in C#



Thanks for posting.  The Contains method requires an argument of the same type that the List is.  So you would have to create a new Contact object to perform the search.  I would advise against this way of searching.  The Contains method will search for a complete, perfect match of objects, not just one field.  A good way to search would be to iterate through the list and compare each object's email address(es) against what you are looking for.  Hope that helps.




Andrew B.

Constant Contact

API Support

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More