Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > FilterExpression Multiple tags

FilterExpression Multiple tags

  • Brendan avatar

    Posted on Feb 18, 2009 (permalink)

    I've seen the examples given on how to use the filterexpression with tags, for instance:

    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name = "mytag"

    I have this working well, but I'd like to be able to use the filterexpression on multiple tags, so that the items (news items in this case) returned by the filterexpression are all identified with each tag in the expression. I've tried using multiple "AND Tag.Name=" and introducing LIKE into the expression for tag.Name, but to no avail. Can this be done, and if so what is the proper syntax?

    Thanks.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 19, 2009 (permalink)

    Hi Brendan,

    In this case filterexpression will not list the items that have been tagged. You should use the intersection approach.

    Here is a sample:

              string Tag1 = tag1; 
            string Tag2 = tag2; 
     
            NewsManager newsManager = new NewsManager("News"); 
            IList listOfAllNews = newsManager.Content.GetContent(0, 0, string.Empty, Tag1); 
            IList listOfAllNews1 = newsManager.Content.GetContent(0, 0, string.Empty, Tag2); 
            // here we are using intersection  
            List<IContent> intersection = new List<IContent>(); 
            foreach (IContent c1 in listOfAllNews) 
            { 
                foreach (IContent c2 in listOfAllNews1) 
                { 
                    if (c1.ID == c2.ID) 
                    { 
                        intersection.Add(c1); 
                        break
                    } 
                     
                    // list the content titles here  
                } 
     
            } 
            foreach (IContent item in intersection) 
            { 
                Response.Write(item.GetMetaData("Title")); 
            } 
        } 
        #region properties 
     
        public string Tag1 
        { 
            get { return this.tag1; } 
            set { this.tag1 = value; } 
        } 
     
     
        public string Tag2 
        { 
            get { return this.tag2; } 
            set { this.tag2 = value; } 
        } 
        #endregion properties 
        #region private fileds 
        private string tag1; 
        private string tag2; 
        # endregion private fileds 


    Best wishes,
    Ivan Dimitrov
    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.

    Reply

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > FilterExpression Multiple tags