Megosztás a következőn keresztül:


How to Import and Export Lists

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

This topic describes how to import and export lists.

To Import and Export lists

  1. In Visual Studio, create a new Commerce Server 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 object.

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

  6. Look up the ID of an existing mailing list definition.

  7. Export the list to a text file.

  8. Create a new StaticList object for importing the text file that was just exported.

  9. Import a previously saved list from ExportList.txt.

Example

The following code example illustrates how to import and export lists. You can view the results in the Commerce Server Marketing Manager application.

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

namespace CommerceServerMarketingExamples
{
    public class CSMarketingExamples
    {
        public void ImportExportsLists()
        {
            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);

                // Look up the ID of an existing mailing list definition.
                SearchClauseFactory searchClauseFactory = marketingSystem.MailingLists.GetSearchClauseFactory();
                SearchClause sc = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "Name", "Test Mailing List");
                DataSet dataSet = marketingSystem.MailingLists.Search(sc);
                Guid listId = (Guid)dataSet.Tables["SearchResults"].Rows[0][0];

                // Export the list to a text file.
                marketingSystem.MailingLists.Export(listId, "c:\\ExportList.txt");

                // Create a new static list for import.
                StaticList sl = marketingSystem.MailingLists.NewStaticList();
                sl.Name = "Imported List";
                sl.Save();

                // Import the list previously exported.
                sl.Import("c:\\ExportList.txt");
            }
            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