More in this section

Forums / Developing with Sitefinity / Best practice for declaring metaFields in code

Best practice for declaring metaFields in code

4 posts, 0 answered
  1. Schneider
    Schneider avatar
    29 posts
    Registered:
    02 Nov 2008
    18 Feb 2009
    Link to this post
    So the ManageBase constructor calls Initialize() which ends up calling OnInitialized() which ends up loading the meta fields declared in the web.config and setting them on the provider.

    All well and good.

    The question is:
    • If I want to define my metafields in code, what is the best practice to do this?
    • Should I override some, hook something, use an event?
    • And where should I do it?

    Thanks
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Feb 2009
    Link to this post
    Hi Jack,

    This is impossible to be done. All meta fields are loaded from the web.config file, even the predefined ones. When Sitefinity is loading, if the metafield is not presented in the web.config file, it does not exist in and for the system.

    Could you elaborate on why do you need such functionality? Perhaps we will find a suggestion for your case.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Schneider
    Schneider avatar
    29 posts
    Registered:
    02 Nov 2008
    24 Feb 2009
    Link to this post
    The most important one is consistency/robustness.

    -We want the same meta data fields on many providers (we don't want to cut and paste because that is error prone)
    -Our application is dependent on these fields so they must be present. Therefore I would rather have them in code than in a config file where they can be broken.
  4. Ricky
    Ricky avatar
    12 posts
    Registered:
    09 Feb 2017
    26 Feb 2009
    Link to this post
    Hello Schneider,

    The best practice for declaring metaFields is obviously web.config. That looks like

    <metaFields>
        <add key="Libraries.MyNewField" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
    </metaFields>


    Now, here "Libraries" is the name of  data provider you set. And now from code you can easliy access

    content.SetMetaData("MyNewFields") = value;

    Hope that helps,
    Mehfuz

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered