1using System;
2using System.Configuration;
3using System.Data;
4using System.Linq;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.HtmlControls;
9using System.Web.UI.WebControls;
10using System.Web.UI.WebControls.WebParts;
11using System.Xml.Linq;
12using etAPI;
13public partial class DataExtensionSendableCreate : System.Web.UI.Page
14{
15 //Global Variables
16 private SoapClient client = new SoapClient();
17 protected void Page_Load(object sender, EventArgs e)
18 {
19 //Authenticate
20 client.ClientCredentials.UserName.UserName = System.Configuration.ConfigurationSettings.AppSettings["wsUserName"];
21 client.ClientCredentials.UserName.Password = System.Configuration.ConfigurationSettings.AppSettings["wsPassword"];
22 if (!IsPostBack)
23 {
24 }
25 }
26 protected void btnSubmit_Click(object sender, EventArgs e)
27 {
28 try
29 {
30 //Create a GUID to ensure a unique subscriber key
31 string strGUID = System.Guid.NewGuid().ToString();
32 //Create DataExtension object [Subscribers > Data Extensions > Data Extensions]
33 DataExtension de = new DataExtension();
34 de.CustomerKey = strGUID;
35 de.Name = strGUID;
36 //Is this data base table going to house Subscribers?
37 de.IsSendable = true;
38 de.IsSendableSpecified = true;
39 //The Name of the Column in the DE to map to ET
40 de.SendableDataExtensionField = new DataExtensionField();
41 de.SendableDataExtensionField.FieldType = DataExtensionFieldType.Text;
42 de.SendableDataExtensionField.Name = "subscriber_key";
43 //The Name of the Attribute to Send to
44 de.SendableSubscriberField = new etAPI.Attribute();
45 de.SendableSubscriberField.Name = "Subscriber Key";//If Subscriber Key is turned on this must be Subscriber Key
46 de.Fields = new DataExtensionField[3];
47 //1
48 //Set the column parameters
49 de.Fields[0] = new DataExtensionField();
50 de.Fields[0].Name = "subscriber_key";
51 de.Fields[0].FieldType = DataExtensionFieldType.Text;
52 de.Fields[0].FieldTypeSpecified = true;
53 de.Fields[0].IsRequired = true;
54 de.Fields[0].IsRequiredSpecified = true;
55 de.Fields[0].IsPrimaryKey = true;
56 de.Fields[0].IsPrimaryKeySpecified = true;
57 de.Fields[0].MaxLength = 200;//If this is the Primary Key MaxLength is required.
58 de.Fields[0].MaxLengthSpecified = true;
59 //2
60 //Set the column parameters
61 de.Fields[1] = new DataExtensionField();
62 de.Fields[1].Name = "email_address";
63 de.Fields[1].FieldType = DataExtensionFieldType.EmailAddress;
64 de.Fields[1].FieldTypeSpecified = true;
65 de.Fields[1].IsRequired = true;
66 de.Fields[1].IsRequiredSpecified = true;
67 //3
68 //Set the column parameters
69 de.Fields[2] = new DataExtensionField();
70 de.Fields[2].Name = "full_name";
71 de.Fields[2].FieldType = DataExtensionFieldType.Text;
72 de.Fields[2].FieldTypeSpecified = true;
73 de.Fields[2].IsRequired = false;
74 de.Fields[2].IsRequiredSpecified = true;
75 try
76 {
77 string cRequestID = String.Empty;
78 string cStatus = String.Empty;
79 //Call the Create method on the Subscriber object
80 CreateResult[] cResults = client.Create(new CreateOptions(), new APIObject[] { de }, out cRequestID, out cStatus);
81 //Display Results
82 lblMessage.Text += "Overall Status: " + cStatus;
83 lblMessage.Text += "<br/>";
84 lblMessage.Text += "Number of Results: " + cResults.Length;
85 lblMessage.Text += "<br/>";
86 //Loop through each object returned and display the StatusMessage
87 foreach (CreateResult cr in cResults)
88 {
89 lblMessage.Text += "Status Message: " + cr.StatusMessage;
90 lblMessage.Text += "<br/>";
91 }
92 }
93 catch (Exception exCreate)
94 {
95 //Set Message
96 lblMessage.Text += "<br/><br/>CREATE ERROR:<br/>" + exCreate.Message;
97 }
98 }
99 catch (Exception exc)
100 {
101 //Set Message
102 lblMessage.Text += "<br/><br/>###ERROR<br/>" + exc.Message;
103 }
104 }
105}