How to Enumerate Available Lists

This topic describes how to enumerate the available lists and change the properties of one of the lists, such as the list name and description.

How to update a list within a list of existing lists

  1. In Visual Studio, create a new Commerce Server Core Systems Web application.

  2. Add the Microsoft.CommerceServer.CrossTierTypes and Microsoft.CommerceServer.Marketing.CrossTierTypes references to the application.

  3. Add a using directive for the Microsoft.CommerceServer and Microsoft.CommerceServer.Marketing namespaces.

  4. Define the Marketing Web Service URL.

  5. Create the MarketingContext.

    For more information, see How to Connect to the Marketing System. In this example, the MarketingContext object is named marketingSystem.

  6. Retrieve a list of existing lists.

  7. Loop through the list descriptions searching for the list described as "Test Mailing List". When you find it, change the name to "Updated Mailing List" and change the description.

Example

The following code example illustrates how to enumerate available lists.

using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;

namespace CommerceServerMarketingExamples
{
    public class CSMarketingExamples
    {
        public void EnumerateAvailableLists()
        {
            try
            {
                // Set the URL to the Web service.
                string marketingWebServiceUrl = @"https://localhost/MarketingWebService/MarketingWebService.asmx";
                // Create an instance of the Marketing System agent.
                MarketingServiceAgent ma = new MarketingServiceAgent(marketingWebServiceUrl);
                MarketingContext marketingSystem = MarketingContext.Create(ma);

                // Find the Test Mailing List.  Change its name and description.
                MailingList[] allMail = marketingSystem.MailingLists.GetAllLists();
                for (int l = 0; l < allMail.Length; l++)
                    if (allMail[l].Name == "Test Mailing List")
                    {
                        allMail[l].Name = "Updated Mailing List";
                        allMail[l].Description = "Updated Mailing List Description";
                        //Save it back to disk.
                        allMail[l].Save();  
                        break;
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
                if (ex.InnerException != null)
                    Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
                Console.ReadLine();
            }
        }
    }
}

See Also

Other Resources

Marketing Management Scenarios