Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, July 22, 2015

How to create subscribers in ExactTarget using C# code



ExactTarget is a cloud service provided by Salesforce for running email campaign for email marketing. For this we need to create subscribers.
 
Here is a code for to create subscribers in ExactTarget via its web service.


Change necessary values in below code and call the method. That’s it.

static void AddSubscribers()
{
    //Account authentication information for an ExactTarget user. Access it from web.config
    SoapClient client = new SoapClient();
    client.ClientCredentials.UserName.UserName = "xyz";
    client.ClientCredentials.UserName.Password = "xyzpassword";

    //Create a new subscriber - person email id
    Subscriber newSub = new Subscriber();
    newSub.EmailAddress = "abc@test.com";
    newSub.SubscriberKey = "abc@test.com";

    //Create the subscriber attributes
    newSub.Attributes = new ExactTargetClient.Attribute[6];

    //Attribute - First Name
    newSub.Attributes[0] = new ExactTargetClient.Attribute();
    newSub.Attributes[0].Name = "First Name";
    newSub.Attributes[0].Value = "Enter your first Name Here";

    //Attribute - Last Name
    newSub.Attributes[1] = new ExactTargetClient.Attribute();
    newSub.Attributes[1].Name = "Last Name";
    newSub.Attributes[1].Value = "Enter your Last Name Here";

    //Attribute - Zip Code
    newSub.Attributes[2] = new ExactTargetClient.Attribute();
    newSub.Attributes[2].Name = "Zip Code";
    newSub.Attributes[2].Value = "110011";

    //Attribute - State
    newSub.Attributes[3] = new ExactTargetClient.Attribute();
    newSub.Attributes[3].Name = "State";
    newSub.Attributes[3].Value = "Johannesburg";

    //Attribute - City
    newSub.Attributes[4] = new ExactTargetClient.Attribute();
    newSub.Attributes[4].Name = "City";
    newSub.Attributes[4].Value = "Johannesburg";

    newSub.Attributes[5] = new ExactTargetClient.Attribute();
    newSub.Attributes[5].Name = "Country";
    newSub.Attributes[5].Value = "South Africa";

    //Specify the busiess unit ID
    newSub.Client = new ClientID();
       //Manage via a config file
    newSub.Client.ID = 1234567; 
    newSub.Client.IDSpecified = true;

    //Declare the list we want to add the subscriber to
    //Please manage these values via a configuration file
    SubscriberList mylist = new SubscriberList();
    mylist.ID = 1234;
    mylist.IDSpecified = true;

    //Relate the List to the Subscriber
    newSub.Lists = new SubscriberList[] { mylist };

    //Instantiate the CreateOptions object for the create call of TSD
    CreateOptions cOptionsTS = new CreateOptions();
    cOptionsTS.RequestType = RequestType.Asynchronous;
    cOptionsTS.RequestTypeSpecified = true;

    SaveOption saveOption = new SaveOption();
    saveOption.SaveAction = SaveAction.UpdateAdd;
    saveOption.PropertyName = "*";
    cOptionsTS.SaveOptions = new SaveOption[] { saveOption };

    try
    {
        //Create the request to add the subscriber
        string tsRequestID = "";
        string tsStatus = "";
        CreateResult[] tsResults = client.Create(cOptionsTS, new APIObject[] { newSub }, out tsRequestID, out tsStatus);

        Console.WriteLine("Overall Status ::: " + tsStatus);
        Console.WriteLine("Number of Results ::: " + tsStatus.Length);

        foreach (CreateResult result in tsResults)
        {
            Console.WriteLine("Status Code and Message ::: " + result.StatusCode + " " + result.StatusMessage);
        }

        Console.ReadLine();

        //Check for Error
        if (tsStatus != "OK") { throw new Exception(); }

    }
    catch (Exception exCreate)
    {
        Console.WriteLine(exCreate.Message);
        Console.ReadLine();
    }
}
 
Please leave your comments or share this code if it’s useful for you.

Saturday, July 18, 2015

How to provide internal and external links in rich text editor of Sitecore


It’s a basic but very useful tip that how to provide internal and external links in Sitecore.

If we are providing contents in rich text editor then it’s possible that it may contain some hyperlinks which targeting either external site or internal pages of same site.

How to do that?

Open rich text editor by clicking “Show Editor” link of rich text field.


As indicated in above image there are two toolbox items.

1.    First one is for inserting Internal links for Sitecore items


2.    Another is for external links from External links manager. As shown in image I provided link details for Google.


 Please leave your comments or share this tip if it’s useful for you.

Wednesday, July 15, 2015

Didn’t getting selected value of JQuery populated dropdownlist on server side



I was working on ASP.NET page which contains Country and State dropdown list. I filled country dropdown using JQuery AJAX. Now on selected value of Country I want to fill related states. I told my manager that it’s a simple task and will complete it in 3 hours including testing.

And next one hour I was just trying to get value of selected country in C# ;)

I tried with ddlCountry.selectedvalue but OMG I was not getting selected value.

How to get the dropdown selected value?

As we are filling dropdown list at client side so server side code don’t have any idea about the filled items. So in this situation use Request object as below

string country = Request[ddlCountry.UniqueID];

Now I was able to get the selected country in C# code.

Keep in mind that after getting value if there is another postback, you will not get the same country from Request[ddlCountry.UniqueID]. So during first time itself keep it in Viewstate so that you can use it after several post back as well.

One last thing, I completed this task in 3 hours as I told to my manager :)

Please leave your comments or share this tip if it’s useful for you.