C# Code Samples not working

Highlighted
Occasional Participant

C# Code Samples not working

I've just downloaded the .NET (C#) Sample Forms (Sample File: NET_Sample_Signup_Forms.zip (591 KB)) but when I unzip and try to open them in Visual Studio 2005 I'm getting an error telling me that it cannot be opened because it was created in a newer version. I've downloaded Visual Studio 2008 & 2010 express and have tried to open in both without success. Does anybody know what version of Visual Studio these samples work in?


Thanks

Todd


 

6 REPLIES 6
Highlighted
CTCT Employee

Re: C# Code Samples not working

Unfortunately this is not something I'm able to replicate. I have Visual Studio 2010 and was able to open the sample code without an issue once the conversion wizard had updated it. I can certainly try downloading the Visual Studio 2010 Express and let you know if I run into any issues though.

David J

Highlighted
CTCT Employee

Re: C# Code Samples not working

I just downloaded Visual Studio 2010 Express and was able to open the project without an issue. Upon opening, it needed to run the built in conversion wizard (same as Visual Studio 2010) but as soon as that was complete I was able to edit and use the project as expected.

David J

Highlighted
Occasional Participant

Thanks for your reply. I've

Thanks for your reply. I've re-dowloaded the zip file and I've been able to open it in Visual Studio Express 2010. Visual Studio runs the conversion wizard and when it's finished I'm able to access the ConstantContactBO project and the ContactContactUtility project but the Development, UploadContactForm and Web project are listed as unavailable. Shouldn't all projects in the solutions be available?


Todd


 

Highlighted
CTCT Employee

Re: Thanks for your reply. I've

It looks like Visual C# Express versions do not support 'Solutions Folders' which is why you're getting an error when importing this project. According to Microsoft, this is by design. I am going to see if I can find some work around to allow this to be imported into the express versions but at the moment all I have been able to find is a VisualStudio 2008 to 2005 Project Converter Utility, which I have not tested myself.

David J

Highlighted
Occasional Participant

Advice on how to proceed.

David, Thanks for your responses. Since I'm using Visual Studio 2005 for development I'm not exactly sure how to proceed. What I need to do is update a contact form I have on my site so on submission it will create a new contact. I was going to base my code off of the samples but without being able to open them up I'm kind of stuck. Any help that you can provide would be greatly appreciated.


Todd 


 

Highlighted
CTCT Employee

Re: Advice on how to proceed.

Unfortunately  I still think that converting the project from 2008 to 2005 might be the best method to proceed forward with this. We are not able to create the projects without using solution folders, and this would involve and entire recreation/refactor of the project. There are many helpful posts regarding this process, including this as well as the one I linked a few posts up. As an alternative, you could try using something more basic such as the following functions to upload your data. This could easily be expanded upon to add more functionality.


public class UploadContact

        {

            string username = "USERNAME";

            string password = "PASSWORD";

            string apikey = "APIKEY";



            public void PostContact(string emailAddress, string firstName, string lastName, int listId)

            {

                //creates XML with firstname, lastname, and email address info.

                StringBuilder XMLData = new StringBuilder();

                XMLData.Append("<entry xmlns=\"http://www.w3.org/2005/Atom\">");

                XMLData.Append("<title type=\"text\"> </title>");

                XMLData.Append("<updated>2008-023T14:21:07-6.407Z</updated>");

                XMLData.Append("<author></author>");

                XMLData.Append("<id>data:,none</id>");

                XMLData.Append("<summary type=\"text\">Contact</summary>");

                XMLData.Append("<content type=\"application/vnd.ctct+xml\">");

                XMLData.Append("<Contact xmlns=\"http://ws.constantcontact.com/ns/1.0/\">");

                XMLData.Append("<EmailAddress>" + emailAddress + "</EmailAddress>");

                XMLData.Append("<FirstName>" + firstName + "</FirstName>");

                XMLData.Append("<LastName>" + lastName + "</LastName>");

                XMLData.Append("<OptInSource>ACTION_BY_CONTACT</OptInSource>");

                XMLData.Append("<ContactLists>");

                XMLData.Append("<ContactList id=\"http://api.constantcontact.com/ws/customers/" + username + "/lists/" + listId.ToString() + "\" />");

                XMLData.Append("</ContactLists>");

                XMLData.Append("</Contact>");

                XMLData.Append("</content>");

                XMLData.Append("</entry>");

                httpPost(XMLData.ToString());

            }



            private void httpPost(string data)

            {

                string URI = "https://api.constantcontact.com/ws/customers/" + username + "/contacts";

                string Login = apikey + "%" + username;

                // Create a request for the URL.

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);

                // Add Request Header

                request.Accept = "application/atom+xml";

                // Set the Method property of the request to POST.

                request.Method = "POST";

                // set the credentials.

                request.Credentials = new NetworkCredential(Login, password);

                // Create POST data and convert it to a byte array.

                string postData = data;

                byte byteArray = Encoding.UTF8.GetBytes(postData);

                // Set the ContentType property of the WebRequest.

                request.ContentType = "application/atom+xml";

                // Set the ContentLength property of the WebRequest.

                request.ContentLength = byteArray.Length;

                // Get the request stream.

                Stream dataStream = request.GetRequestStream();

                // Write the data to the request stream.

                dataStream.Write(byteArray, 0, byteArray.Length);

                // Close the Stream object.

                dataStream.Close();

                // Get the response.

                WebResponse response = request.GetResponse();

                // Display the status.

                Console.WriteLine(((HttpWebResponse)response).StatusDescription);

                // Get the stream containing content returned by the server.

                dataStream = response.GetResponseStream();

                // Open the stream using a StreamReader for easy access.

                StreamReader reader = new StreamReader(dataStream);

                // Read the content.

                string responseFromServer = reader.ReadToEnd();

                // Display the content.

                Console.WriteLine(responseFromServer);

                // Clean up the streams.

                reader.Close();

                dataStream.Close();

                response.Close();

                MessageBox.Show(responseFromServer);

            }

        }

David J

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured