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

Forums / Developing with Sitefinity / Associating library documents to external data

Associating library documents to external data

2 posts, 0 answered
  1. clayman
    clayman avatar
    38 posts
    Registered:
    23 Sep 2009
    16 Oct 2009
    Link to this post
    I'm converting an existing site to run within Sitefinity.  Some content needs to remain in external databases, while other content (as much as possible) will be maintained within Sitefinity either as Generic content (for text) or Document Libraries (for .pdfs).

    Something I am struggling with right now is how to associate documents to the external content. 

    To explain:
    (1) my pdf lives in a document library in Sitefinity, and my products come from a products database.
    (2) I need to display a page where I list my products and one of the columns should be a link to the product document (which would come from the document library).
    (3) Seems that if I were to create a tag with the product's ID, I could then query a the document library and retrieve the document(s) that were tagged with the ID (and some other tags or categories which in combination would be unique), and get the url from the correct document.

    ...this seems easy enough, but I am not finding any snippets to illustrate how this can be achieved in the Sitefinity API.

    Here's some imaginary code (3rd line is what I'm stuck on) that should explain what I need to do... please advise.  Thanks!

    protected string GetDocumentUrl(string productID)
    {
            LibraryManager libraryManager = new LibraryManager();
            
            ILibrary library = libraryManager.GetLibrary("MyDocumentLibrary");

            CmsContentBase document = library.GetItems(new Tag(productID))[0];

            return document.Url;
    }


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Oct 2009
    Link to this post
    Hi clayman,

    First you need to create some bridge relation between your products data and IContent object from Image and Documents.

    In your case you can use two repeaters where the first one will be bound to your Products and the second 9 which will be inside the first one) will be bound to Images and Documents items.

    <asp:Repeater ID="lists" runat="server">
        <ItemTemplate>
         <asp:Literal ID="ShowProductsContent" runat="server" /></h2>
            <asp:Repeater ID="ShowIContentObject" runat="server">
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="DownLoadDocument" runat="server" />
                    </li>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:Repeater>

    For instance you could create a new metakey for documents items which will be used to store the data - product ID for your products. By doing so you will associate certain product with certain document.

    Then when you bind the repeater you will show the metadata and if the products id is the same is this from the metakey you will show the hyperlink that points to associated document

    pseudo code

    protected virtual void ShowIContentObject_ItemDataBound(object sender, RepeaterItemEventArgs e)
           {
               if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
               {
                   IContent documentItem;
                   HyperLink DownLoadDocument;
                   if (documentItem.GetMetaData("ProductID").ToString() == productID)
                   {
                       DownLoadDocument.NavigateUrl = documentItem.UrlWithExtension;
                   }
                   else
                   {
                       DownLoadDocument.Visible = false;
                   }
      
               }
      
         }

    in Sitefinity backend you can add a control - say RadCombobox that will be bound to your products - Name and ID so you can easily make a bridge relation.

    I hope this helps.

    Best wishes,
    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.
2 posts, 0 answered