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

Forums / Developing with Sitefinity / How to get hold of documents inside Liabrary

How to get hold of documents inside Liabrary

6 posts, 0 answered
  1. Raghu
    Raghu avatar
    19 posts
    Registered:
    21 Jun 2010
    14 Dec 2010
    Link to this post
    Hi ,

    I have created a liabrary in modules section which contains around 4 to 5 .doc files.
    I have plugged this liabrary to one of the page that I am about to publish. I want to capture metadata of these files and also the contents of these files when I publish the page so that I can process this data to some xml file.

    For the same reason I have subscribed to executed event in global.asax file. Here I will look into page's control collection to fetch the liabrary metadata and files contents along with it.


    void CmsManager_Executed(object sender, Telerik.ExecutedEventArgs e)
    {
        var content = e.Data as Telerik.Cms.Data.CmsPageContent;
        var pageControls = content.CmsPage.Controls;
       foreach (Telerik.Cms.ICmsWebControl control in pageControls) 
       
            // get the liabrary object from page control collection and process the data
       }
    }

    But somehow I am not able to fetch contents and metadata using above method.

    Could you please help me in resolving this issue?

    Thanks,
    Raghu

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Dec 2010
    Link to this post
    Hello Raghu,

    There is a better way to do this.

    1. Create a custom class that inherits from ImageGallery
    2. Override SetItemMetadata or CreateDataSource method from where you can get the content items.
    3. You can get the current page from CmsUrlContext.Current and detect the page status of the page on which you have dropped your custom ImageGallery control.

    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
  3. Raghu
    Raghu avatar
    19 posts
    Registered:
    21 Jun 2010
    15 Dec 2010
    Link to this post

    Hi Ivan ,

    Thanks for your response.

    Do you mean that I should create a custom module altogather which will inherit from Telerik.Libraries.DownloadList.

    And this module I will use to create document liabrary ?


    Thanks and Regards,
    Raghu

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Dec 2010
    Link to this post
    Hello Raghu,

    DownloadList is a control , so you do not need to have a custom module. You have to inherit from this class - Telerik.Libraries.Download list and follow the suggestions from my previous post ( step 2 and 3).


    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. Raghu
    Raghu avatar
    19 posts
    Registered:
    21 Jun 2010
    15 Dec 2010
    Link to this post

    HI Ivan,

    I have created custom control which inherits from Telerik.Libraries.DownloadList control.

    public class CustomLiabrary : Telerik.Libraries.DownloadList 

    I have also overridden following methods.

    SetItemMetadata

    CreateDataSource

    Also I added this control at toolboxControls section in web.config file so that I can drag and drop the control on page. When I drop this control on page I get list of documents already uploaded in document library which is fine.

    Next what I want is when user hits on Publish button I want to capture all these documents’ metadata along with their content if possible and store it in some xml file for some other use. So I am trying to do this in CmsManager_Executed in global.asax file. I didn’t get why we need to override above methods? My simple requirement is to fetch list of documents on that page and capture their contents and metadata while user publish it and store it to some xml file.

    Thanks,
    Raghu 

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Dec 2010
    Link to this post
    Hello Raghu,

    1. If the control is dropped on a page, CrateDataSource is called, so you can add the data to your XML.
    2. The way you use ( through Executed event in Global.asax) require  using reflection which is not supported in Medium Trust

    foreach (ICmsWebControl c in p.Controls)
           {
               if (c.ControlType.FullName.Equals("Telerik.Libraries.WebControls.DownloadList"))
               {
                   var view = c.LoadControl();
                   var flags =  BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
                   var me = view.GetType().GetMethods(flags).Where(m=>m.Name == "CreateDataSource" && m.GetParameters().Length == 0).Single();
                   var res = me.Invoke(view, null);
      
               }
           }


    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
Register for webinar
6 posts, 0 answered