More in this section

Forums / Developing with Sitefinity / Get contents from a single document library programmatically

Get contents from a single document library programmatically

7 posts, 2 answered
  1. xor
    xor avatar
    42 posts
    Registered:
    04 Jan 2010
    01 Apr 2010
    Link to this post
    Hi,

    I am using Images and Documents module to create libraries of different types and i would use the default DownloadList to display the content from a particular library programmatically.

    I created a class that inherits from the Download List:

    ToolboxItem(typeof(MyDownloadListToolboxItem))]
    public class MyDownloadList : Telerik.Libraries.DownloadList
    .....

     

    I Know that i can use the code below to get a specific library content but i am not sure how to do this in my class.

    libraryManager.GetContent(0, 0, "Publication_Date DESC", this.GetLibraryID(LibraryName));
      
    private Guid GetLibraryID(string libraryName)
    {
          return libraryManager.GetLibrary(libraryName).ID;
    }

     

     

    any help is appreciated.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Apr 2010
    Link to this post
    Hi Fadi Raheel,

    You could override CreateDataSource() method and paste the code you have ther. By doing so the control will be bound to the list of the returned items.

    sample

    protected override IList CreateDataSource()
    {
     
        var list= libraryManager.GetContent(0, 0, "Publication_Date DESC", this.GetLibraryID(LibraryName));
        if(list.count >0)
          return list;
         
     
         // else return base.CreateDataSource()
    }
     
    private Guid GetLibraryID(string libraryName)
    {
       return libraryManager.GetLibrary(libraryName).ID;
    }



    Kind 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.
    Answered
  3. xor
    xor avatar
    42 posts
    Registered:
    04 Jan 2010
    01 Apr 2010
    Link to this post
    Hi Ivan Dimitrov,

    I tried your code and it helped getting content based on a library name, but my design requires that the user selects the library (and other filtering data) from a dropdown and clicks on a search button to get the desired result.
    Since CreateDataSource() method fires early in the control's events life cycle, I can not get the user selection.

    any advice?




  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Apr 2010
    Link to this post
    Hello Fadi Raheel,

    You could call CreateDataSource() once again after you have the proper data ( your users selects some values, then in the code CreateDataSource() is called)

    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.
  5. xor
    xor avatar
    42 posts
    Registered:
    04 Jan 2010
    01 Apr 2010
    Link to this post
    Calling the CreateDataSource() again from an action event will not bind the returned result to the DownloadList. This could be helpfull if I can get a reference to the DownloadList's internal grid.

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    01 Apr 2010
    Link to this post
    Hello Fadi Raheel,

    The control does not use any grid. It uses Repeater control. As I see it you are inheriting from DownloadList class, so you are able to control what will be bound and when.

    Kind 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.
    Answered
  7. xor
    xor avatar
    42 posts
    Registered:
    04 Jan 2010
    01 Apr 2010
    Link to this post
    Thank you Ivan,

    the following code did it.

    [Browsable(false)]
    public Repeater RepeaterControl
    {
        get
        {
            return base.ListContainer.GetControl<Repeater>("repeater", false, Telerik.Framework.Web.TraverseMethod.DepthFirst);
        }
    }
    private void SearchButton_Command(object sender, CommandEventArgs e)
    {
        this.RepeaterControl.DataSource = CreateDataSource();
        this.RepeaterControl.DataBind();
    }
Register for webinar
7 posts, 2 answered