Author Archives: Erik Nordin Wahlberg

Get LinkURL to another language

I’ve had some problem to link to a page to another language then the current language.
Even though I have a PageData-object with anouther languagebranch, it stills makes a link to the current language.

My own solution, building a url by CurrentPage.StaticLink and adding epslanguage=langID, works but it’s not how I want to do it.

So today I found the EPiServer.UriSupport class. In that class you have EPiServer.UriSupport.AddLanguageSelection(pd.LinkURL, pd.LanguageID), just what I’ve been looking for.

New AppSettings/Dynamic List (one option) and AppSettingsMultiple/Dynamic list (Multiple options) in EPiServer CMS 5

The new properties AppSettings and AppSettingsMultiple in EPiServer CMS 5 is a pretty nice feature, but when yesterday when I tried to implement it, I had a hard time finding out how to do it. But finally I did.

First of all, in edit mode, AppSettings will create a DropDown and AppSettingsMultiple will create a CheckBoxList.

To create you AppSettings property you have to define some values in <appSettings> in your Web.Config, i did like this:
<add key=”PropertyCountries” value=”Czech republic;CR|Sweden;SV|United Kingdom;UK” />

Now you just have to add a Property to your pagetype with the name PropertyCountries and you are done.

When you use the AppSettingsMultiple the CurrentPage.Property[“PropertyCountries”].Value will return a comma separated string with the selected values, like “SV,UK” and you just have to do a simple .Split(‘,’) and you have a string array.

Custom property – DropDown

Made my first customized property today, and because I loved it so much in 4.6, the ice breaker was a DropDown property that takes values from the help-text.

Values in help text can be typed in two ways:
“Shown text:value” or just “value” eg. “value1;Shown text:value2”

[Serializable]
[PageDefinitionTypePlugIn]
class PropertyDropDown : EPiServer.Core.PropertyString
{

public override EPiServer.Core.PropertyData ParseToObject(string value)
{
PropertyDropDown prop = new PropertyDropDown();
prop.String = value;
return prop;
}

public override EPiServer.Core.IPropertyControl CreatePropertyControl()
{
// Create an instance of MyCustomPropertyControl that is used
// for displaying the property.
return new PropertyDropDownControl();
}
}

class PropertyDropDownControl : EPiServer.Web.PropertyControls.PropertyDataControl
{
DropDownList dd;

public PropertyDropDown PropertyDropDown
{
get
{
return PropertyData as PropertyDropDown;

}
}

public override void CreateEditControls()
{
dd = new DropDownList();
this.ApplyControlAttributes(this.dd);
Controls.Add(dd);
this.SetupEditControls();
}

public override void CreateOnPageEditControls()
{
dd = new DropDownList();
this.ApplyControlAttributes(this.dd);
Controls.Add(dd);
this.SetupEditControls();
}

protected override void SetupEditControls()
{
dd.Items.Clear();
string[] values = PropertyDropDown.TranslateDescription().Split(';');
foreach (string value in values)
{
ListItem li = new ListItem();
if (value.Contains(":"))
{
li.Text = value.Split(':')[0];
li.Value = value.Split(':')[1];
}
else
{
li.Text = value;
li.Value = value;
}

li.Selected = li.Value.Equals(PropertyDropDown.Value);
dd.Items.Add(li);
}

if (dd.Items.Count == 0)
dd.Items.Add(new ListItem("No values found", ""));
}

public override void ApplyEditChanges()
{
base.SetValue(this.dd.SelectedValue);
}

public override void ApplyOnPageEditChanges()
{
base.SetValue(this.dd.SelectedValue);
}
}
}