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

Forums / Developing with Sitefinity / setting document list filter expression programatically

setting document list filter expression programatically

8 posts, 0 answered
  1. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    04 Feb 2009
    Link to this post
    I have created a UserControl which contains two controls:
        1) a dropdown list that will be used as a filter
        2) the sfLib:DownloadList that will display a list of documents in my library

    I have also created a new MetaData called 'PublishDate'.  This date indicates when a given document was published.

    The idea of the control is to display all documents in my library (sorted by publish date) and allow the user to filter the documents based on publish year.

    I have managed to display all the documents in the library.
    I have managed to extract the minimum and maximum years and populated my dropdown list with the range of years.

    However, I am having difficulty setting the FilterExpression on the DownloadList.

    In the DropDownList_ItemChanged event, I am setting the DownloadList.FilterExpression as given in this code:

    protected void ddlFilterList_SelectedIndexChanged(object sender, EventArgs e)
    {
    //filter the list based on the selected year
    if (ddlFilterList.SelectedValue == "0")
    {
    downloadListTableFiltered.FilterExpression = string.Empty;
    }
    else
    {
    DateTime yearStart = new DateTime(Int32.Parse(ddlFilterList.SelectedValue), 1, 1);
    DateTime yearEnd = new DateTime(Int32.Parse(ddlFilterList.SelectedValue), 12, 31);

    downloadListTableFiltered.FilterExpression =
    String.Format("PublishDate >= \"{0}\" AND PublishDate <= \"{1}\"",
    yearStart.ToShortDateString(), yearEnd.ToShortDateString());
    }

    }

    I get the following error on the web page:

    Left operand 'PublishDate' is not supported. Supported left operands are :
    Name
    Description
    Author
    Category
    ID
    Tag.ID
    Tag.Name
    ParentID
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 Feb 2009
    Link to this post
    Hello michael,

    You need to set the provider name that will be used from DownloadList control. You could do this in the template or in the code behind.

    downloadListTableFiltered.ProviderName = "Libraries"

    Otherwise GenericContent provider is set and the error you get is thrown. Just to let you know in Design mode of DownloadList control you could set the provider under Advanced tab, Data.

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    21 Dec 2009
    Link to this post
    I want to filter Download lists in such a way that I can filter on a tag (that is the same as page.theme) and at the same time get items that are not tagged. If I try this, I get an error "ContentFilterStatement is not Valid":

    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", Page.Theme, ContentFilter.Condition.Equal, ContentFilter.JoinType.And)); 
    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", String.Empty, ContentFilter.Condition.Equal, ContentFilter.JoinType.And)); 

    Any suggestions?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Dec 2009
    Link to this post
    Hello David Meyer,

    The filter seems to be correct. Can you send the code sample that you use to filter the list?

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    21 Dec 2009
    Link to this post
    So I can filter Tag.Name with String.Empty? I was thinking that is what is throwing errors.

            public void SetFilters(string LibraryName, bool IsMini) 
            { 
                //mini documentlist, how many items to display is in config file 
                if (IsMini) 
                { 
                    int MiniListMaximumCount = !String.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["MiniListMaximumCount"]) ? Int32.Parse(System.Configuration.ConfigurationSettings.AppSettings["MiniListMaximumCount"]) : 0; 
                    if (MiniListMaximumCount > 0) 
                    { 
                        this.LimitListCount = true
                        this.MaximumListCount = MiniListMaximumCount
                    } 
                } 
     
                //Set filtering based on page theme... page theme is set also by querystring in InternalPage 
                ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this); 
                filterBuilder.ClearFilter();  
                 
                if (this.Page != null && !String.IsNullOrEmpty(this.Page.Theme)) 
                { 
                    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", Page.Theme, ContentFilter.Condition.Equal, ContentFilter.JoinType.And)); 
                    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", string.Empty, ContentFilter.Condition.Equal, ContentFilter.JoinType.And)); 
                } 
                //and filter by Library name.  
                LibraryManager manager = new LibraryManager(); 
                ILibrary documentLibrary = manager.GetLibrary(LibraryName); 
                string libraryid = documentLibrary.ID.ToString(); 
                if (libraryid != null) 
                { 
                    string leftOperand = "ParentID"
                    string rightOperand = libraryid
                    ContentFilter.Condition condition = ContentFilter.Condition.In; 
                    ContentFilter.JoinType join = ContentFilter.JoinType.And; 
                    ContentFilterStatement statement = 
                        new ContentFilterStatement(leftOperand, rightOperand, condition, join); 
                    filterBuilder.AddFilter(statement); 
                } 
            } 

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Dec 2009
    Link to this post
    Hello David Meyer,

    The problem is that you cannot use String.Empty or "" for the right operand. There should be a value there, event not correct tag, so the control will not show anything.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    21 Dec 2009
    Link to this post
    Right. So back to the original question, if I want to filter for specific tagged items AND items that do not have a tag, how would I do that?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Dec 2009
    Link to this post
    Hello David Meyer,

    There is no straight forward way to do this. Below is a sample code that illustrates desired behavior. There are two lists - with tagged and not tagged content.

    var manager = new ContentManager("Generic_Content");
           IList contentItems = manager.GetContent();
           IList allTags = manager.GetTags();
           List<IContent> taggedContentList = new List<IContent>();
           List<IContent> NotTagged = new List<IContent>();
           foreach (ITag tag in allTags)
           {
               IList taggedContent = tag.TaggedContent;
               foreach (ITaggedContent tgdCnt in taggedContent)
               {
                   IContent content = manager.GetContent(tgdCnt.ContentID);
                   if (content != null)
                   {
                       taggedContentList.Add(content);
                   }
               }
           }
           foreach (IContent content in contentItems)
           {
               if (!taggedContentList.Contains(content))
                   NotTagged.Add(content);
            
           }
     

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
8 posts, 0 answered