How to Create a List in the Marketing System
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
You can create lists from a text file, a comma-separated values (CSV) file, an Expression, or the StaticList object. This topic describes how to create a list named TestMailingList from a file that is named TestMailingList.csv. After you create the list, you import the list of e-mail addresses from the file.
To create a list
In Visual Studio, create a new Commerce Server Web application.
Add the Microsoft.CommerceServer.CrossTierTypes and Microsoft.CommerceServer.Marketing.CrossTierTypes references to the application.
Add a using directive for the Microsoft.CommerceServer and Microsoft.CommerceServer.Marketing namespaces.
Define the Marketing Web Service URL.
Create the MarketingContext.
For more information, see How to Connect to the Marketing System. In the example, the MarketingContext object is named marketingSystem.
Create the TestMailingList.csv text file.
The example file below contains the e-mail addresses for a group of users. This is the minimum row information that you need for every record. There are five available fields per record in this order: E-mail Address, Message Format, Language, URL, and Character Set. Only E-mail Address is required; the other four fields are optional. See List and Direct Mail Management Programming Concepts for addition field information.
joeuser@treyresearch.com barneyuser@fabrikam.com bettyuser@adventure-works.com jackuser@contoso.com jilluser@northwindtraders.com
Create a new StaticList mailing list object.
Import the TestMailingList.csv list that you created in step 6 into the Static List object that that you created in step 7.
Example
The following code examples illustrate how to create a list in the marketing system.
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;
namespace CommerceServerMarketingExamples
{
public class CSMarketingExamples
{
public void NewList()
{
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);
// Create a new mailing list.
StaticList sl = marketingSystem.MailingLists.NewStaticList();
sl.Name = "Test Mailing List";
sl.Description = "This is a description for a test mailing list";
// Save the new list.
sl.Save();
Guid listId = sl.Id;
// Import a list of email addresses for the new mailing list.
string ListFileName = "c:\\TestMailingList.csv";
sl.Import(ListFileName);
}
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();
}
}
}
}