June 6, 2016

Setup Selenium for .Net application

If you want to setup Selenium and want to get more information about it, visit below URL to get information about it.
http://www.seleniumhq.org/

Above Site provides all setup information about Selenium.
Once you download Selenium Standalone server, you have to start it.

To Start Selenium Standalone server use below command on command prompt.
You need to install Java latest version.

java –jar D:\Software\Selenium\selenium-server-standalone-2.53.0.jar.

February 28, 2016

Read Key value from Sitecore config File

Lets see how can we read key value from config file.
string
dbName = Sitecore.Configuration.Settings.GetSetting("DB");

Your config file will contain content something like this.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

  <sitecore>

    <settings>

      <setting name="DB" value="ITDetails"/>

    </settings>

  </sitecore>

</configuration>

February 27, 2016

Create Custom Validator in Sitecore WFFM

Sample code snippet to create custom validator in Sitecore WFFM.

public class CustomCountryValidator : FormCustomValidator
   
{

       
protected override bool EvaluateIsValid()
       
{
            var form
= WebUtil.GetParent<SimpleForm>(this);
            var field
= (CustomDropListCountryPicker)WebUtil.FindFirstOrDefault(form, c => c is CustomDropListCountryPicker && (c as CustomDropListCountryPicker).Result.FieldName == "ddlCountry");
           
            Control controlToValidate
;
           
string value;

           
if (!String.IsNullOrEmpty(base.ControlToValidate))
           
{
                controlToValidate
= this.FindControl(base.ControlToValidate);
                value
= HttpContext.Current.Request[controlToValidate.UniqueID];

               
if(condition)
                   
return true;
           
}
           
return false;
       
}

   
}

February 26, 2016

Create Custom Condition in Sitecore WFFM

Sample code snippet to create custom condition in Sitecore WFFM

public class CustomCondition<T> : StringOperatorCondition<T> where T : RuleContext
   
{

       
public string FieldName
       
{

            get
;
            set
;
       
}
       
public string Value
       
{

            get
;
            set
;
       
}
       
protected override bool Execute(T ruleContext)
       
{
           
if (Condition > 0)
           
{
               
return true;
           
}
           
return false;
       
}
   
}  

February 25, 2016

Pre populate field value in Sitecore WFFM

In order to pre populate values in Sitecore WFFM, we can create custom action for this. Sample code to pre populate values in Sitecore WFFM

public class SampleCustomAction<T> : RuleAction<T> where T : ConditionalRuleContext
   
{

       
public override void Apply(T ruleContext)
       
{
            Item FieldItem
= null;
           
if (ruleContext.Control is IResult)
           
{
                FieldItem
= GetItemFromDatabase(Sitecore.Context.Database.Name, ((IResult)ruleContext.Control).FieldID);
               
if (FieldItem != null)
               
{
                   
string FieldValue = GetFieldValueFromDB(((IResult)ruleContext.Control).ControlName);
                   
((IResult)ruleContext.Control).DefaultValue = FieldValue;
               
}
               
return;
           
}
       
}

       
public Item GetItemFromDatabase(string database, string FormUri)
       
{
            Sitecore
.Data.Database db = Sitecore.Configuration.Factory.GetDatabase(database);
           
return db.GetItem(FormUri);
       
}

       
public string GetFieldValueFromDB(string fieldName)
       
{
           
string FieldValue = string.Empty;
           
return FieldValue;
       
}
   
}


February 24, 2016

Create Custom Hidden Field in Sitecore WFFM

Sample code to create a custom Hidden field in Sitecore WFFM.

public class CustomHiddenEmailfield : SingleLineText
   
{

       
protected override void OnInit(EventArgs e)
       
{
           
this.Attributes.Add("style", "display: none;");
           
this.textbox.CssClass = "scfSingleLineTextBox";
           
this.help.CssClass = "scfSingleLineTextUsefulInfo";
           
this.generalPanel.CssClass = "scfSingleLineGeneralPanel";
           
this.title.CssClass = "scfSingleLineTextLabel";
           
this.textbox.TextMode = TextBoxMode.SingleLine;
           
this.Controls.AddAt(0, (Control)this.generalPanel);
           
this.Controls.AddAt(0, (Control)this.title);
           
this.generalPanel.Controls.AddAt(0, (Control)this.help);
           
this.generalPanel.Controls.AddAt(0, (Control)this.textbox);
       
}
   
}