I have set up a widget for the backend of my Sitefinity site that has three textboxes and a button. The goal is to create a new column in the database:
protected void btnAddClick(object sender, EventArgs e)
{
Type TelerikType = Type.GetType(txtTelType.Text);
Type ColumnType = Type.GetType(txtColType.Text);
string error = "";
if (TelerikType == null)
{
error = "Telerik Type is invalid";
}
if (ColumnType == null)
{
error = "Column Type is invalid";
}
if (error.Length == 0)
{
App.WorkWith()
.DynamicData()
.Type(TelerikType)
.Field()
.TryCreateNew(txtName.Text, ColumnType)
.SaveChanges(true);
error = "Added column successfully";
txtColType.Text = txtName.Text = txtTelType.Text = "";
}
literalErrorText.Text = string.Format(literalErrorText.Text, error);
}
I am having two problems:
When I enter Telerik.Sitefinity.Pages.Model.PageNode into the textbox, Type.GetType(txtTelType.Text) is returning null.
If I replace that portion with typeof(PageNode) I get "Specified type 'Telerik.Sitefinity.Pages.Model.PageNode' is not a dynamic type."
I'm hoping somebody might have some insight as to why these things wouldn't work correctly, or possibly a better way to approach this issue? For reference, my goal (at least for now) is to add a dynamic column that references PageNode so that I can specify a ShowInLeftNavigation boolean and a ShowInRightNavigation boolean. Thank you for any help you can provide.
Read the docs carefully here:
typeName Type: System.String The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.
So if the type is not one of the base .Net types, or in the currently executing assembly, you have to tell GetType what assembly to look in as well. I don't know what assembly the Telerik control are in, but it looks like you will have to add the assembly to the type name, something linke this:
TopNamespace.SubNameSpace.ContainingClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089
Follow the link for "AssemblyQualifiedName" above to get all the gory details of the syntax.