This page is intended to help users use the ASP Upload Form sample application.
Users will have to set up the API Key, account Username and Password in order to access the Constant Contact resources. The following features are available: add a new Contact (using the full or simplified from), search for a Contact and then add it or update it (both Contact adding or updating is performed using the simplified from), remove a Contact from all lists and unsubscribing a Contact (opted-out Contacts become members of the "Do-Not-Mail" special list).
To set up the authentication data, you need to change the following keys from the web.config file, found in the project:
Users can create a new Contact by filling out the full or the simplified form . For the full form they can provide the following informations for the new Contact: Email Address, First Name, Last Name, Middle Name, Home Phone, Address, City, State/Province, Zip/Postal Code, Sub Zip/Postal Code, Country, Company Name, Job Title, Work Phone, Email Format, Notes, Custom field 1 - 15 and Contact Lists on which the newly Contact would receive occasional email.
Required fields are: Email Address and at least one Contact List should be checked.
For the simplified form they can provide the following informations for the new Contact: Email Address, First Name, Last Name, Middle Name, Home Phone, Address, City, State/Province, Zip/Postal Code, Sub Zip/Postal Code, Country and Contact Lists on which the newly Contact would receive occasional email.
Required fields are: Email Address and at least one Contact List should be checked.
If the contact does not exist or does not belong to “Do-Not-Mail” list, the contact will be added to the chosen lists and you are given the message below.
Note that this only works for a brand new contact that does not belong to any list. If a contact already exists, in any contact list, then you are notified that the contact already exists. To update an existing contact to another list, then you have to go into “Update” mode as described below.
The Add or Edit a Contact section allows users to write an e-mail address and sign it up into their constant account. After clicking the Sign Up button the written e-mail address is searched in the user Constant Contact account.
If the e-mail address does not exist, then users are automatically redirected to the page that allows them to create a new Contact using the simplified form. On the create new Contact form, the E-mail Address field is automaticaly filled with the e-mail address provided on the Add or Edit a Contact page. You can enter Contact informations in this form and after that, pressing the Add Contact button will create the desidered Contact in your Constant Contact account.
If the e-mail address exists, then users are automatically redirected to the page that allows them to update that Contact using the simplified form. Using this screen, you can now edit each field as well as unsubscribe the Contact from a list by un-checking a list and subscribe to a list by checking it.
The Sign Up form consists of the following web page sources: SearchContact.aspx, SearchContact.aspx.cs, AddContactSmallForm.aspx, AddContactSmallForm.aspx.cs, UpdateContactSmallForm.aspx, UpdateContactSmallForm.aspx.cs and the master page (Master.master and Master.master.cs). The master page contains the menu items and the Constant Contact company logo.
In order use the Sign Up form on your web site you should follow these steps:
1: <configuration>
2: <appSettings>
3: <!--API Application Key and is used to identify the application making an API request-->
4: <add key="APIKey" value=""/>
5: <!--Constant Contact Customers user name-->
6: <add key="username" value=""/>
7: <!--Constant Contact Customers password-->
8: <add key="password" value=""/>
9: </appSettings>
10: </configuration>
If you open the SearchContact.aspx web page from your project it should display a content similar with the image above only if you imported also the master page. If you don't import the master page then the SearchContact.aspx web page should not display the menu items and the Constant logo.
The Sign Up button click event handler code is described below:
1: /// <summary>
2: /// Search button click event handler
3: /// </summary>
4: /// <param name="sender"></param>
5: /// <param name="e"></param>
6: protected void btnSearch_Click(object sender, EventArgs e)
7: {
8: if (!Page.IsValid)
9: {
10: return;
11: }
12:
13: string[] emailAddress = new string[] {txtEmail.Text.Trim()};
14: try
15: {
16: string nextChunkId;
17: // search Contact by email
18: IList<Contact> list = Utility.SearchContactByEmail(AuthenticationData, emailAddress, out nextChunkId);
19: if (list.Count != 0)
20: {
21: // save Contact Id to be updated into Session
22: Session.Add("ContactIdToUpdate", list[0].Id);
23: // redirect to update Contact
24: Response.Redirect("~/UpdateContactSmallForm.aspx");
25: }
26: else
27: {
28: // save the Contact E-mail Address
29: Session.Add("NewContactEmailAddress", txtEmail.Text.Trim());
30: // redirect to add Contact
31: Response.Redirect("~/AddContactSmallForm.aspx");
32: }
33: }
34: catch (ConstantException ce)
35: {
36: #region display alert message
37:
38: StringBuilder stringBuilder = new StringBuilder();
39: stringBuilder.Append(@"<script language='javascript'>");
40: stringBuilder.AppendFormat(@"alert('{0}')", ce.Message);
41: stringBuilder.Append(@"</script>");
42: ClientScript.RegisterStartupScript(typeof (Page), "AlertMessage", stringBuilder.ToString());
43:
44: #endregion
45: }
46: }
After the e-mail address is validated then it is stored into a variable (line 13). The utility method Utility.SearchContactByEmail performs the search and returns a collection of Contacts that exists with the e-mail address the user provided (line 18). If the returned collection is not empty (the collection items count is different than 0) then it means that a Contact with that e-mail address exists and the user is redirected to the update page (line 24). If the returned collection is empty (items count is equal with 0) then there is no Contact with specified e-mail address and the user is redirected to the add Contact simplified form (line 31). In case of REST API communication errors a message is displayed to the user, lines from 36 to 44.
The List all Contacts option will display all contacts that the acount owner have. Edition of a contact can be performed by clicking on the Edit link. The Remove link will remove the contact from all lists. Since the Constant Contact REST API uses chunk data, this page also displayes information using chunks (50 contacts on page). The Next link, below the table, will perform another query that will retrieve from the Constant Contact server next 50 contacts and if you press it again it will display the next 50 contacts. When there are no next contacts, then the link it will be automaticaly disabled. The First link will get the first 50 contacts from the server and you will be able after that to get the next available contacts from the server (if there is the case).
Using the update form (simplified form - from the Add or Edit Contact menu item or full form - from the List all Contacts menu item) users have an option to unsubscribe it all lists using the "Unsubscribe me from all lists" check box marked in the image below. Checking this will remove the contact from all lists and add the user to the "Do-Not-Mail" list.
Using the List all Contacts, users can remove a Contact (removing it from all lists) by clicking the Remove link. The Contact Status will be changed from Active to Removed. Only contacts that are Active can be unsubscribed from all lists. To change the status of a removed contact, click the Edit link, subscribe it to any list(s) and update it's profile. The status of the contact will be changed from Removed to Active.
ASP upload form uses the following types:
In the Release/Setup folder, double click the setup.exe to begin the installation of ASP Net Sample application.
Click the Next button then choose the Site where this application will be installed. Also the Virtual directory name can be specified.
Pressing the Next button will guide you to the Confirmation Step. Pressing again the Next button will start the installation process. After it is completed press the Close button to close the wizard.
Before staring the sample API Key, Username and Password must be defined. To do that, you should edit the web.config configuration file from the %SystemDrive%\Inetpub\wwwroot\UploadContactForm folder.
Note: If you changed the Virtual directory when installing the sample then you should found the web.config file in the following folder %SystemDrive%\Inetpub\wwwroot\[virtual_directory] ([virtual_directory] it should mach the folder you specified for the Virtual directory).
Open the configuration file and edit the following key values: APIKey, username, password.
In order to customize the displayed lists you will need to make some changes in the ConstantContact class from the ConstantContact.cs file, found in the App_Code folder of the ASP solution. The prefiltering is disabled by default and to enable it you need to make minor changes. Right now the prefiltering method contains the following code:
1: /// <summary>
2: /// Prefilter the Contact Lists
3: /// </summary>
4: /// <param name="contactLists"></param>
5: /// <returns></returns>
6: public static IEnumerable<ContactList> PrefilterContactLists(IEnumerable<ContactList> contactLists)
7: {
8: return contactLists;
9:
10: //// define the collection of lists name do you want
11: //string[] prefilterNames = new string[] { "List 1", "List 2", "List 3" };
12:
13: //foreach (ContactList contactList in contactLists)
14: //{
15: // foreach (string contactListName in prefilterNames)
16: // {
17: // if (string.Equals(contactList.Name, contactListName, System.StringComparison.Ordinal))
18: // {
19: // yield return contactList;
20: // }
21: // }
22: //}
23: }
To enable it you need to comment the line number 8 and uncomment the lines 10-22. If you do that, then the Contact Lists displayed on the forms are filtered and only those that have the name equal with "List 1", "List 2" and "List 3" are shown.
1: /// <summary>The prefilterNames string array stores Contact List names that you want to display on the forms. If you change the array items, let's say add another one with the name "List 4", then, only Contact Lists that have the name equal with "List 1", "List 2", "List 3" and "List 4" are shown.
2: /// Prefilter the Contact Lists
3: /// </summary>
4: /// <param name="contactLists"></param>
5: /// <returns></returns>
6: public static IEnumerable<ContactList> PrefilterContactLists(IEnumerable<ContactList> contactLists)
7: {
8: //return contactLists;
9:
10: // define the collection of lists name do you want
11: string[] prefilterNames = new string[] { "List 1", "List 2", "List 3" };
12:
13: foreach (ContactList contactList in contactLists)
14: {
15: foreach (string contactListName in prefilterNames)
16: {
17: if (string.Equals(contactList.Name, contactListName, System.StringComparison.Ordinal))
18: {
19: yield return contactList;
20: }
21: }
22: }
23: }
The [BaseFolder]\ASPSample.sln file represents the Visual Studio 2005 solution project for this application and is composed of three projects: two class library projects (ConstantContactBO and ConstantContactUtility) and the web project itself (ConstantContactBO - provides access to the following .NET wrapper objects: Contact Lists and Contacts;ConstantContactUtility - provides access to utility methods to create a new Contact, update an existing one, search Contact by email, etc).
The ConstantContactBO project consists of the following files: Contact.cs (contains information's about a Constant Contact), ContactList.cs (contains information's about a Constant Contact List) and one class diagram file named ClassDiagram.cd that describes the structure of theConstantContactBO project.
The ConstantContactUtility project consists of the following files: ContactComponent.cs (contains class used parse response streams into Contacts, creates entries for creating and updating Contacts, etc.), ContactListComponent.cs (contains class used to parse response streams into Contact Lists, creates entries for creating and updating Contact Lists, etc.), AuthenticationData.cs (contains class used to store API Key, username and password for the Constant Contact REST API), Utility.cs (provides utility methods to create a new Contact, update an existing one, search by email, etc.) and one class diagram file named ClassDiagram.cd that describes the structure of the ConstantContactUtility project.
The web project consists of the following files:
If you want to import pages from this sample into your web site, you need to:
1: <configuration>
2: <appSettings>
3: <!--API Application Key and is used to identify the application making an API request-->
4: <add key="APIKey" value=""/>
5: <!--Constant Contact Customers user name-->
6: <add key="username" value=""/>
7: <!--Constant Contact Customers password-->
8: <add key="password" value=""/>
9: </appSettings>
10: </configuration>