Getting List of custom table field names

Lea Lebonski asked on March 17, 2021 13:49

Hi there,

just a quick question. I am trying to input excel data into Kentico custom table based on the fields which are already there to save me extending the model every time they change the excel file.

For that, I am trying to get a list of all field names of a custom table to assign values from excel accordingly. Is there an easy way how to get this? I had a look at DataClassInfoProvider but I can't seem to get the desired result. Have you got any tips for this or indeed a preferred method you use to achieve results in similar scenarios? E.g. Excel input into the Kentico custom table?

Thanks,

Lea

Correct Answer

Dmitry Bastron answered on March 17, 2021 14:57

Hi Lea,

It's possible to get a list of fields for class via these 2 options:

Parse and analyze form definition

var dataClass = DataClassInfoProvider.GetDataClassInfo("your.custom.table.class.name");
var classDefinition = dataClass.ClassFormDefinition;

Look through "search settings" as a workaround

var dataClass = DataClassInfoProvider.GetDataClassInfo("your.custom.table.class.name");
foreach (var field in dataClass.ClassSearchSettingsInfos)
{
    var fieldName = field.FieldName;
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brian McKeiver answered on March 17, 2021 14:08

Have you considered using the Kentico Import Toolkit? It is a windows app that can import excel files to custom tables. Or do you need to do this programmatically through the API ?

1 votesVote for this answer Mark as a Correct answer

Lea Lebonski answered on March 17, 2021 14:28

Hi Brian,

yes I do need to do it via API I am afraid as the file is downloaded via scheduled task every morning and I want to extend that task to import the excel data into Kentico to feed the website automatically.

Thank you.

0 votesVote for this answer Mark as a Correct answer

Lea Lebonski answered on March 19, 2021 10:38

Thanks a lot Dmitry.

Exactly what I needed! :-) It lets me iterate through the document and assign the right data to the right column in the custom table. Thanks for help. :-)

Lea

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.