You are currently browsing the daily archive for 8 February, 2008.
After som searching i found this EPiServer forum thread that show how to create a custom property in CMS 5. Not rocket sience, but I like to have one place to find code samples that will speed up my work. With this new blog I have just such a place
using System;
using System.Collections.Generic;
using System.Text;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.PlugIn;
using EPiServer.Web.PropertyControls;
using System.Web.UI.WebControls;namespace EPiServerDemo.PropertyTypes
{
/// <summary>
/// Custom PropertyData implementation
/// </summary>
[Serializable]
[PageDefinitionTypePlugIn(DisplayName="My demo dropdown")]
public class MyDropDownCore : EPiServer.Core.PropertyString
{
public override IPropertyControl CreatePropertyControl()
{
return new MyDropDownPropType();
}
}
public class MyDropDownPropType : EPiServer.Web.PropertyControls.PropertySelectControlBase
{
protected override void SetupEditControls()
{
base.SetupEditControls();DropDownList inputControl = this.EditControl;
inputControl.Items.Add("Red");
inputControl.Items.Add("Blue");
inputControl.Items.Add("Green");
inputControl.SelectedValue = this.PropertyData.Value as string;
}
}
}
In .Net 3.0 you use the ConfigurationManager class, found in the System.Configuration namespace, to get a hold of your applications configuration. You need to make a reference to the System.Configuration.dll
To get your AppSettings, use the following line of code:
string MyString = System.Configuration.ConfigurationManager.AppSettings["keyname"].ToString();
To get you connection strings, use:
string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
and add one node in web.config:
<connectionStrings>
<add name="connstr" connectionString=""/>
</connectionStrings>
