1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Programmatically set category for content item

Programmatically set category for content item

7 posts, 0 answered
  1. Jeremy
    Jeremy avatar
    37 posts
    Registered:
    18 Jan 2011
    21 Nov 2008
    Link to this post

    Hi,

    I've created a custom module based off of the Products Module example. I've created my own page that creates product items. I'm trying to figure out how to set the category for a new item being created. Here is an example of what I'm doing now.

    mobjProductMgr = New Telerik.Cms.Engine.ContentManager("Products")  
    Dim newContent As Telerik.Cms.Engine.IContent = mobjProductMgr.CreateContent("text/html")  
            With newContent  
                .Content = txtItemDescription.Text.Trim  
                ' set meta keys for the content item  
                .SetMetaData("Name", txtItemName.Text.Trim)  
                .SetMetaData("Price", txtItemPrice.Text.Trim)  
                .SetMetaData("ContactName", txtContactName.Text.Trim)  
                .SetMetaData("City", txtCity.Text.Trim)  
                .SetMetaData("State", txtState.Text.Trim)  
                .SetMetaData("Phone", txtPhone.Text.Trim)  
                .SetMetaData("Notes", txtNotes.Text.Trim)  
            End With 
     
            'save the content  
            mobjProductMgr.SaveContent(newContent, ContentStatus.Draft) 


    Thanks for any help,

    Jeremy W.
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    21 Nov 2008
    Link to this post
    Hi Jeremy Wadsworth,

    The Category is also a metafield, so you could set up as you set the rest of the metafields:
    .SetMetaData("Category", objCategory.Value) 

    I hope this helps.




    Sincerely yours,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Jeremy
    Jeremy avatar
    37 posts
    Registered:
    18 Jan 2011
    21 Nov 2008
    Link to this post
    Is this the same way to set a tag. Also, how do I specify multiple Categories or tags?

    Thanks,

    Jeremy
  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    21 Nov 2008
    Link to this post
    tags are not meta items, but are instead handled by the contentmanager. here's some links that show you how to do this programatically:

    http://www.sitefinity.com/help/developer-manual/tags-create.html
    http://www.sitefinity.com/help/developer-manual/tags-update.html
    http://www.sitefinity.com/help/developer-manual/tags-delete.html

    categories however, are currently one-to-one, so each item can be assigned to only one category...

    I hope this was helpful!
  5. Jeremy
    Jeremy avatar
    37 posts
    Registered:
    18 Jan 2011
    21 Nov 2008
    Link to this post
    Thank you. Both replies have been most helpful.

    Jeremy
  6. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    21 Nov 2008
    Link to this post
    Hi Guys,

    And how to read the Category and tags added to the contents in the admin side of ControlPanelEdit/Insert templates used in GC Modules? I use one external database to link some services and I can catch the values of this items.
    Many thanks.
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Nov 2008
    Link to this post
    Hi Pierre,

    If you use the out of the box control templates, you may try to create a code behind for them. Then our APIs and the docs which were mentioned here would help you.

    All the best,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
7 posts, 0 answered