The following code snippet demonstrates how to get the StartDate
and EndDate
for a Commerce Server Discount
. This assumes you are using the Commerce Server 2007 API and that you know the ID of the discount you want the dates from.
//The discount id we want to get dates from.
var discountId = 12;//Set to your ID.
//Configure the Commerce Server site name.
var siteName = "StarterSite";
//We need a MarketingContext instance so we can access the marketing API.
var mc = MarketingContext.Create(siteName, null, AuthorizationMode.NoAuthorization);
//Get our discount.
var discount = (Discount)mc.CampaignItems.GetCampaignItem(discountId);
//Voila. Start and End dates.
var startDate = discount.StartDate;
var endDate = discount.EndDate;
Note: The MarketingContext.Create
overload, returns a MarketingContext
instance that utilises the marketing system management API in local mode. For more information on these modes, see Understanding the Different Types of Commerce Server APIs.