forked from campaignmonitor/createsend-dotnet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jason Hickey
committed
Nov 26, 2010
1 parent
40c6584
commit a27d6c3
Showing
4 changed files
with
138 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using createsend_dotnet; | ||
|
||
namespace Samples | ||
{ | ||
public class ListSamples | ||
{ | ||
private string listID = "your_list_id"; | ||
|
||
void CreateCustomField() | ||
{ | ||
List list = new List(listID); | ||
|
||
try | ||
{ | ||
string newCustomFieldKey = list.CreateCustomField("NewCustomField", CustomFieldDataType.Text, null); | ||
Console.WriteLine(newCustomFieldKey); | ||
} | ||
catch (CreatesendException ex) | ||
{ | ||
ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; | ||
Console.WriteLine(error.Code); | ||
Console.WriteLine(error.Message); | ||
} | ||
catch (Exception ex) | ||
{ | ||
//handle some other failure | ||
} | ||
} | ||
|
||
void CreateMultiOptionCustomField() | ||
{ | ||
List list = new List(listID); | ||
|
||
try | ||
{ | ||
List<string> options = new List<string>() { "Option 1", "Option 2", "Option 3" }; | ||
string newCustomFieldKey = list.CreateCustomField("NewCustomField", CustomFieldDataType.MultiSelectOne, options); | ||
Console.WriteLine(newCustomFieldKey); | ||
} | ||
catch (CreatesendException ex) | ||
{ | ||
ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; | ||
Console.WriteLine(error.Code); | ||
Console.WriteLine(error.Message); | ||
} | ||
catch (Exception ex) | ||
{ | ||
//handle some other failure | ||
} | ||
} | ||
|
||
void GetActiveSubscribers() | ||
{ | ||
List list = new List(listID); | ||
|
||
try | ||
{ | ||
List<SubscriberDetail> allSubscribers = new List<SubscriberDetail>(); | ||
|
||
//get the first page, with an old date to signify entire list | ||
PagedCollection<SubscriberDetail> firstPage = list.Active(new DateTime(1900, 1, 1), 1, 50, "Email", "ASC"); | ||
|
||
allSubscribers.AddRange(firstPage.Results); | ||
|
||
if(firstPage.NumberOfPages > 1) | ||
for (int pageNumber = 2; pageNumber <= firstPage.NumberOfPages; pageNumber++) | ||
{ | ||
PagedCollection<SubscriberDetail> subsequentPage = list.Active(new DateTime(1900, 1, 1), pageNumber, 50, "Email", "ASC"); | ||
allSubscribers.AddRange(subsequentPage.Results); | ||
} | ||
|
||
//we can now do whatever with every subscriber | ||
foreach(SubscriberDetail subscriberDetail in allSubscribers) | ||
Console.WriteLine(subscriberDetail.EmailAddress); | ||
} | ||
catch (CreatesendException ex) | ||
{ | ||
ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; | ||
Console.WriteLine(error.Code); | ||
Console.WriteLine(error.Message); | ||
} | ||
catch (Exception ex) | ||
{ | ||
//handle some other failure | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters