Get url of document referenced in custom module

Posted by Community Admin on 04-Aug-2018 20:23

Get url of document referenced in custom module

All Replies

Posted by Community Admin on 04-May-2012 00:00

Hi,

I have a custom module with a field that has a reference to a document, specifically a PDF file I have uploaded to Sitefinity.  I also have a custom widget to render this module to the page.  I want to be able to create a hyperlink to the PDF file of the current module but am having trouble extracting it when using a <%# Eval %> tag.

Thanks,
Richard

Posted by Community Admin on 07-May-2012 00:00

I still haven't been able to come up with what I consider the correct way to do this but I have narrowed down the issue and come up with a work around.

I originally had tried using a sitefinity:AssetField control with the DataFieldName set to the attribute name of the module's document link.  But this caused a type error because the control apparently was trying to convert the Document to an Image.  So I specified the DataFieldType to telerik's Document class and that still didn't work.

So through some digging I found out that the actual object being stored was an array of ContentLink objects.  If the custom module had an attached document, it was stored at index 1.    But the only way I could get to the underlying Document object for it's URL was to get the Guid from the ContentLink.ChildItemId property and then pass it to a LibrariesManager object calling GetDocument.  I created a utility method in my code behind and am now calling this inside an <%# %> eval tag in order to get the document's URL inside the link.

So in short I have a work-around but it is not as elegant a solution as I would like.

Posted by Community Admin on 07-May-2012 00:00

Richard, I'm sorry I didn't get a chance to reply to your post sooner. however, you have indeed discovered the best way to currently do this kind of databinding in a custom control or template.

Using a helper method is the same process I used for this blog post: Retrieving Data From Dynamic Modules Using the Module Builder API. the example uses an image, but the process is the same, as all media items are stored as an array of Guids. As you mentioned, if a single item is specified, the array will be one item long, and be in the first index.

The module builder team is aware of this limitation and I am confident that they are addressing the issue. I'm not sure if this will be improved in the next release but I do know they are working on it. Thank you kindly for your feedback about this, and for updating the community with your progress!

Posted by Community Admin on 07-May-2012 00:00

Thanks, I'll keep an eye out for any updates but it's good to know I was completely off base in my work-around.

Posted by Community Admin on 15-May-2012 00:00

Hi @SelAromDotNet and Richard,
I am also stuck to the kind of same problem. I have a list of employees where each employee has a document uploaded for it and instead of ussing Sitefinity Assetfield I am using a Link Button. On Link button click i am throwing my own implementation of email verification with JQuery. In my code behind I can get hold on to the "GetDataItems" that return me the collection of employees but when I go for "GetDataItem" it also ask me to provide the "GUID ID" that I dont have and in my code snippet the <%# Eval("Id") %> is the GUID ID, i-e. holding the collection (array) of guids and I dont know how to get the specific clicked guid from here.  Could you please give me some idea how I can get hold on to the document that I clicked so that I can get this document downloaded in my code behind file? Any help will really be appreciated. Following is my code snippet

<telerik:RadListView ID="dynamicContentListView" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
    <LayoutTemplate>
        <ul class="employee-list">
            <asp:PlaceHolder ID="ItemsContainer" runat="server" />
        </ul>
    </LayoutTemplate>

        <ItemTemplate>
      <li class="employee">
          <h2 class="sfitemTitle">
              <sf:DetailsViewHyperLink ID="DetailsViewHyperLink" TextDataField="Title" runat="server" />
          </h2>
          <sf:AssetsField ID="AssetsField1" runat="server" DataFieldName="Picture"  CssClass="employee-image"/>
          <sf:SitefinityLabel ID="SitefinityLabel1" runat="server" Text='<%# Eval("Designation")%>'  WrapperTagName="div" HideIfNoText="true" CssClass="sfitemShortTxt" />          
          <sf:SitefinityLabel ID="SitefinityLabel2" runat="server" Text='<%# Eval("CompanyName")%>' WrapperTagName="div" HideIfNoText="true" CssClass="sfitemShortTxt" />
         
   <div id="evalid" runat="server">
              <%# Eval("Id") %>
          </div>
         
 <asp:LinkButton Runat="server" ID="DownloadLnkButton" Text="Download" CssClass="employee-document"/>
      </li>
    </ItemTemplate>
</telerik:RadListView>

<div class="dialogTest" visible="false"> <br /><br />
    Please enter your email address: <asp:TextBox CausesValidation="true" ID="txtEmailAddress" runat="server" style= "Width: 300px;" /> <br/>

    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
        ControlToValidate="txtEmailAddress" ErrorMessage="Email is required" />
   
    <asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1"
        ControlToValidate= "txtEmailAddress"
        ErrorMessage="Please enter a valid email address!"
        ValidationExpression= "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]1,3\.[0-9]1,3\.[0-9]1,3\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]2,4|[0-9]1,3)(\]?)$"/> <br/>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true"/>
</div>

<script type="text/javascript">
    $j = jQuery.noConflict();
    $j(document).ready(function ()
        $j(".employee-image img, .employee-document").click(function ()
            $j(".dialogTest").addClass("open");
        );
    );
</script>

Posted by Community Admin on 20-Dec-2013 00:00

I'm having the same problem. Is it possible to get the document url from the widget template without modifying code behind?  I don't have access to the code behind (that I know of) and our IT staff will not likely be able to help out.   Any way to access the data just via the template widget and maybe some js or am I out of luck?

Posted by Community Admin on 20-Dec-2013 00:00

Hi Matt, you might be able to find what you need by using the AssetsField control on the widget template. You can find out more about that control in this thread: www.sitefinity.com/.../module-builder-and-images

I hope this is helpful!

Posted by Community Admin on 30-Dec-2013 00:00

Thanks for the Reply. I am trying to use the AssetsField but it is not showing the link to the document.  I think it may have something to do with the difference between RadListView and DynamicDetailContainer.  I am trying to get it to show up on RadListView, I don't need a details page, but when I do have a details page it seems to show up fine.  Below is my template code. It doesn't throw an error however nothing shows up for the BillInsert AssetField. Any idea what would cause that issue?

<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<telerik:RadListView ID="dynamicContentListView" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
    <LayoutTemplate>
        <ul class="sfitemsList sfitemsListTitleDateTmb">
            <asp:PlaceHolder ID="ItemsContainer" runat="server" />
        </ul>
    </LayoutTemplate>
    <ItemTemplate>
        <li class="sfitem sfClearfix">
            <sf:ImageAssetsField runat="server" DataFieldName="Thumbnail" IsThumbnail="False" />
            <sf:AssetsField runat="server" DataFieldName="BillInsert" id="BillInsert" />
            <h2 class="sfitemTitle">
                <sf:DetailsViewHyperLink ID="DetailsViewHyperLink" TextDataField="Title" runat="server" />
            </h2>
            <sf:FieldListView ID="PublicationDate" runat="server" Format="PublicationDate.ToLocal():MMM d, yyyy, HH:mm tt" WrapperTagName="div" WrapperTagCssClass="sfitemPublicationDate" />
        </li>
    </ItemTemplate>
</telerik:RadListView>
<sf:Pager id="pager" runat="server"></sf:Pager>
<asp:PlaceHolder ID="socialOptionsContainer" runat="server"></asp:PlaceHolder>

Posted by Community Admin on 02-Jan-2014 00:00

Hello,

The approach with using AssetsField is correct and applying it at my end I am able to render the link to a document as well for an image as shown in your widget template.
Here is a video of the behavior at my end.

I think there is either cache or a glitch that prevents the rendering of the rendering of the document link. I suggest removing the ImageAssetsField form the widget template and then saving it. The image will be removed and I think must refresh the widget template and the link to document will show. After this add the ImageAssetsField control again to the template.

Regards,
Stanislav Velikov
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 02-Jan-2014 00:00

Hi Stanislav, thanks for the reply. It turns out that the link was working and showing up, it's the fact that I was looking at the page in Preview and the link wouldn't show up there for some reason. as soon as I published the page, it started working.

Posted by Community Admin on 02-Jan-2014 00:00

I was able to get the document link from the widget template using <sf:assetfield>, but is there a way to also get the document's file size?  Much like what is displayed in the document download list widget?

Posted by Community Admin on 07-Jan-2014 00:00

Hi,

The size can be retrieved with getting the first document in the BillInsert field and the property ChildItemAdditionalInfo

<%# Eval("BillInsert[0].ChildItemAdditionalInfo") %>"
which holds info for the selected document which consists of the below string
Fiele.docx (826 KB )
If suitable add this string to the control.

Otherwise if manipulating the string with javascript is not suitable another approach to retrieve this to create customized template for module builder based on the instructions in this blog post and retrieve the BillInsertField from each item and read its ChildItemAdditionalInfo property to extract the document filesize.

A sample on doing this as described in the blog post is below:

void repeater_ItemDataBound(object sender, RadListViewItemEventArgs e)
        
            if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem)
            
                //geting the controls on the template from event args as below
                var dataItem = e.Item as RadListViewDataItem;
                if (dataItem.DataItem != null)
                
                    //this is the dynamic item that is currently bound to the list of items
                    var item = dataItem.DataItem as DynamicContent;
                    //get the BillInsertField
                    var customField = item.GetValue("BillInsert");
                    object[] array = (object[])customField;
                    object value = array[0];
                    var actualFieldObject = (ContentLink)value;
 
                    //get ChildItemAdditionalInfo object
                    var imageUrl = actualFieldObject.ChildItemAdditionalInfo;
                     
                    if (item != null)
                    
                        var detailLink = e.Item.FindControl("DetailsViewHyperLink") as DetailsViewHyperLink;
                        var repeat = e.Item.FindControl("RepeaterControl") as Repeater;
                    
                
            
        




Regards,
Stanislav Velikov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed