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

Forums / Developing with Sitefinity / Deleting a Tag pragmatically

Deleting a Tag pragmatically

4 posts, 0 answered
  1. Doug
    Doug avatar
    34 posts
    Registered:
    20 Apr 2010
    11 Jun 2010
    Link to this post
    Hello,
    I am working with the Content API, specifically with the News Provider, and I can't seem to find any method that will allow me to remove a tag from a specified IContent item.  The ContentManager provides a DeleteTag method but this appears to remove the Tag from SiteFinity and not from a Content item. Could you point me in the right direction?

    Edit:
    Also in this vein I am adding a 'ContentView' control to the page pragmatically.  This works fine but, I am assuming, that DetailSettings and MasterSettings are supposed to be populated with some sort of value to control what elements are displayed in the various views. Unfortunately the most information I could find on Settings of any type was the SummarySettings field which seemed to do me no good.  Essentially I just want the Summary, Title, and Date to be displayed on this control.

    Thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Jun 2010
    Link to this post
    Hello Doug,

    There is not method that allows you to delete the Tag only from the content item. When the content item is saved we the ContentTagEditor throws an event where populates a list of ITags - if the list is empty there is no tag associated with the content item and this is why the Tag is not deleted when you are working with the backend.

    Below is a sample code

    // tagsControl  is ContentTagEditor control
    IContentTagEditor tgs = tagsControl as  IContentTagEditor;
    // subscribe for ChangedEventHandler.
    tgs.Changed += new ContentTagEditor.ChangedEventHandler(tgs_Changed);
    tgs.ProviderName = "Generic_Content";
    // cnt is an IContent object
    if (cnt != null)
        tgs.ContentId = cnt.ID;
      
         
        void tgs_Changed(object sender, ContentTagEditor.TagEditorChangedEventArgs e)
        {
            this.SelectedTags = e.selectedTags;
        }
      
        public List<string> SelectedTags
        {
            get
            {
                object obj = ViewState["SelectedTags"];
                if (obj != null)
                    return (List<string>)obj;
                return null;
            }
            set
            {
                ViewState["SelectedTags"] = value;
            }
        }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Doug
    Doug avatar
    34 posts
    Registered:
    20 Apr 2010
    11 Jun 2010
    Link to this post
    Hi Ivan,
       Thanks for that.  I switched to using a combination of Categories and Tags to achieve what I needed to in light of this.  Also in this vein I am adding a 'ContentView' control to the page pragmatically.  This works fine but, I am assuming, that DetailSettings and MasterSettings are supposed to be populated with some sort of value to control what elements are displayed in the various views. Unfortunately the most information I could find on Settings of any type was the SummarySettings field which seemed to do me no good.  Essentially I just want the Summary, Title, and Date to be displayed on this control.  For the time being I "hacked" it by adding the control templates into my configuration file then going in and wrapping the fields I didn't want displayed with <div style="display:none;"> but I would like to know the proper way of doing it. 

    Thanks.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Jun 2010
    Link to this post
    Hello Doug,

    The better way is to create a custom control that inherits from ContentView and expose several public properties of type Boolean. Each property will be used for setting whether the Title, Date and  Summary will be visible. You have to override SetItemMetadata method from where you could access each controls inside the repeater that displays ContentView items list.  You can access all controls from the itemContainer that is parameter of SetItemMetadata method. Depending on the value of the boolean type properties you will show/hide the Title, Summary, Date.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
4 posts, 0 answered