Querying campaigns

To find a specific campaign, you use the NewslettersManager class. The following code finds a campaign with the specified ID through the Native API.

public Campaign QueryCampaign(Guid id)
{
    NewslettersManager manager = NewslettersManager.GetManager();
    Campaign campaign = manager.GetCampaigns().Where(c => c.Id == id).SingleOrDefault();
 
    return campaign;
}

First, you initialize the NewslettersManager. Then, you call GetCampaigns to retrieve all campaigns. Finally, you filter the campaigns based on the Id property.

TIP: You can filter by any of the Campaign properties.

Another way is to use the GetCampaign method of the manager class:

public Campaign QueryMessageBody(Guid id)
{
    NewslettersManager manager = NewslettersManager.GetManager();
    Campaign campaign = null;
 
    try
    {
        campaign = manager.GetCampaign(id);
    }
    catch (ItemNotFoundException e)
    {
        //implement logic regarding the missing item.
    }
 
    return campaign;
}

NOTE: If no campaign with the specified ID exists, the GetCampaign method throwsTelerik.Sitefinity.SitefinityExceptions.ItemNotFoundException exception.

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK