這應該工作:
string classname = "classname";
DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(classname);
if (dci != null)
{
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
if (fi != null)
{
// Field definition
FormFieldInfo ffi = new FormFieldInfo();
ffi.Name = "FieldName";
ffi.AllowEmpty = true;
ffi.System = false;
ffi.FieldType = CMS.FormEngine.FormFieldControlTypeEnum.UploadControl;
ffi.Visible = true;
ffi.Caption = "Field Caption";
ffi.Enabled = true;
// Set whatever properties are relevant to you
fi.AddFormItem(ffi);
TableManager tm = new TableManager(null);
tm.AddTableColumn(dci.ClassTableName, ffi.Name, "uniqueidentifier", true, null);
dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);
dci.ClassFormDefinition = fi.GetXmlDefinition();
// Update DataClassInfo object
DataClassInfoProvider.SetDataClassInfo(dci);
// Update inherited classes with new field
FormHelper.UpdateInheritedClasses(dci);
}
}
您可以隨時檢查上Kentico DevNet版本之間的API的變化。