[Umbraco] Add more than one TinyMCE datatype on page or usercontrol

        private void addTinyMCEControl(Control targetPlaceHolder, TabPage tp)
{

DataTypeDefinition htmlEditorDataType =
DataTypeDefinition.GetDataTypeDefinition(new Guid("A521511A-7BEE-4C5B-8D7B-4B06B57392B3"));

//The other way can get datatype id directly.
//DataTypeDefinition htmlEditorDataType = DataTypeDefinition.GetDataTypeDefinition(-87);

TinyMCE umbracoTinyMCEEditor = (TinyMCE)htmlEditorDataType.DataType.DataEditor;

string toolbar_id = string.Empty;

if (umbracoTinyMCEEditor != null)
{
if (umbracoTinyMCEEditor.config["umbraco_toolbar_id"] != null)
umbracoTinyMCEEditor.config.Remove("umbraco_toolbar_id");
toolbar_id = "tinyMCEMenu_" + targetPlaceHolder.ClientID;
umbracoTinyMCEEditor.config.Add("umbraco_toolbar_id", toolbar_id);
targetPlaceHolder.Controls.Add(umbracoTinyMCEEditor);
tp.Menu.NewElement("div", toolbar_id, "tinymceMenuBar", 0);
}
}


Reference:


[LINQ] Get child controls


using System.Collections.Generic ;
using System.Linq;
///
/// Get all child & sub-child controls within a control by type
///

/// The control we're searching in form/page.
/// The control type we're looking for (i.e; TextBox)
///
public IEnumerable < Control > GetAllChildControls(Control control, Type type = null)
{
var controls = control.Controls.Cast< Control >();

if (type == null)
return controls.SelectMany(ctrl => GetAllChildControls(ctrl, type)).Concat(controls);
else
return controls.SelectMany(ctrl => GetAllChildControls(ctrl, type)).Concat(controls).Where(c => c.GetType() == type);
}



//How to use.
IEnumerable< Control > textBoxControls = GetAllChildControls(this, typeof(TextBox));
IEnumerable< Control > allConrols = GetAllChildControls(this);


Reference : http://www.dreamincode.net/code/snippet5634.htm

[Reflection] Get and Set values of Properties


object sampleObj = new object();
foreach (PropertyInfo info in sampleObj.GetType().GetProperties())
{
// To Get value
if (info.CanRead)
{
object o = info.GetValue(sampleObj, null);
}


// To Set value
object myValue = "Something";
if (info.CanWrite)
{
info.SetValue(sampleObj, myValue, null);
}
}