More in this section

Forums / Developing with Sitefinity / What am I not understanding about the fluent api?

What am I not understanding about the fluent api?

4 posts, 0 answered
  1. Jeff
    Jeff avatar
    6 posts
    Registered:
    30 Nov 2011
    16 Dec 2011
    Link to this post
    Hi guys, 

    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:

    1. When I enter Telerik.Sitefinity.Pages.Model.PageNode into the textbox, Type.GetType(txtTelType.Text) is returning null.

    2. 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.

  2. Jeff
    Jeff avatar
    6 posts
    Registered:
    30 Nov 2011
    16 Dec 2011
    Link to this post
    I figured out what I was doing wrong with the TelerikType, I needed to qualify it with an assembly name, so I changed it thusly: 
                          var assembly = typeof(Telerik.Sitefinity.News.Model.NewsItem).Assembly;
                Type TelerikType = Type.GetType(txtTelType.Text + ", " + assembly.ToString());
    I would still appreciate a better approach if anybody has any ideas, and I would still appreciate help on the second question, which is 
    to say, why isn't pagenode dynamic? Where do I add a column to pages, and how do I access it after I do that? I'm sorry if this is clear
    in the documentation, I can't seem to find the right information in there.
                
  3. Jeff
    Jeff avatar
    6 posts
    Registered:
    30 Nov 2011
    19 Dec 2011
    Link to this post
    I guess what I'm really after here is why is PageNode not a dynamic type, and what dynamic type should I use here to attach a column to pages.
  4. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    21 Dec 2011
    Link to this post
    Hi Jeff,

     The type you need to use is PageData, not PageNode. Can you check the following thread, that describes the same problem and provides solution:
    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/bugs-issues/custom-fields-for-pages.aspx 
    If you have any further questions, please do not hesitate to write back.

    Kind regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered