Here's a snippet from my CSV Import module (on the market place), with the CSV importer i have to list all of the fields a class has, so you can leverage this to do the same! I cut out some of the unimportant stuff.
// Get fields
DataClassInfo ClassObject = DataClassInfoProvider.GetDataClassInfo("Custom.MyClass");
XmlDocument ClassFormXml = new XmlDocument();
ClassFormXml.LoadXml(ClassObject.ClassFormDefinition);
var PrimaryKeyFieldNode = ClassFormXml.SelectSingleNode("/form/field[@isPK='true']");
string PrimaryKeyFieldName = "";
if (PrimaryKeyFieldNode != null)
{
PrimaryKeyFieldName = PrimaryKeyFieldNode.Attributes["column"].Value;
}
// loop through fields, creating a Label and drop down for each
foreach (XmlNode fieldNode in ClassFormXml.SelectNodes("/form/field"))
{
string FieldName = fieldNode.Attributes["column"].Value;
string FieldCaption = (fieldNode.SelectSingleNode("./properties/fieldcaption") != null ? fieldNode.SelectSingleNode("./properties/fieldcaption").InnerText : FieldName);
// These are usually fields that are automatically added by Kentico
bool IsAutoField = false;
if (FieldName == PrimaryKeyFieldName || FieldName.EndsWith("CreatedBy") || FieldName.EndsWith("ModifiedBy") || FieldName.EndsWith("CreatedWhen") || FieldName.EndsWith("ModifiedWhen") || FieldName.EndsWith("GUID"))
{
IsAutoField = true;
}
bool required = false;
if (fieldNode.Attributes["alloweempty"] != null)
{
required = ValidationHelper.GetBoolean(fieldNode.Attributes["alloweempty"].Value, false);
}
}
This loops through the form fields, but you can adjust the SelectNodes xpath expression if you just want to find a specific field or what not.