0
votes

I want to a Pdf field in this module. I want to reach pdf full url and name but don't know how to do in sitefinity. Can somebody help me?

asp.x

<asp:Repeater ID="rptList" runat="server" OnItemDataBound="rptList_ItemDataBound">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
        <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
        <asp:Label ID="lblSummary" runat="server" Text='<%# Eval("Content") %>'></asp:Label>
        <div>
            <asp:Repeater ID="rptPdfList" runat="server" >
                <HeaderTemplate>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="hlSubMenu" runat="server" Text='<%# Eval("Name") %>' NavigateUrl='<%# Eval("Url") %>'
                            onclick='return handleHyperLinkClick(this)'></asp:HyperLink>
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                </FooterTemplate>
            </asp:Repeater>
        </div>
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>

.cs

private Guid guid { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string id = Request.QueryString["id"];

            guid = new Guid(id);
            var myCollection = GetDataItems();

            rptList.DataSource = myCollection;
            rptList.DataBind();
        }
    }

    public IQueryable<DynamicContent> GetDataItems()
    {
        DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
        Type newsReleasesType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.NewsReleases.NewsReleases");
        var myCollection = dynamicModuleManager.GetDataItems(newsReleasesType).Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Id == guid);
        return myCollection;
    }

    protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataTable dtChildNodes = new DataTable();
        dtChildNodes.Columns.Add("Name", typeof(string));
        dtChildNodes.Columns.Add("Url", typeof(string));

        var myCollection = GetDataItems();

        foreach (var mp in myCollection)
        {
            ContentLink cl = ((ContentLink[])mp.GetValue("Pdf"))[0];
            dtChildNodes.Rows.Add(cl.ChildItemProviderName, cl.ChildItemAdditionalInfo);
        }

        Repeater rpt = (Repeater)e.Item.FindControl("rptPdfList");
        rpt.DataSource = dtChildNodes;
        rpt.DataBind();
    }
1

1 Answers

0
votes

you're definitely on the right track! the ContentLink[] is how the media is stored, because it's actually storing a reference to a library item.

You simply need to pass the ChildItemId from the content link (c1.ChildItemId) to a LibraryManager.Get method (like GetImage or GetDocument) to get the actual content item.

From there you can simply do Content.Url to get the actual link to the library item.

There is an example of this on the Sitefinity blogs here: http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2012/01/19/retrieving_data_from_dynamic_modules_using_the_module_builder_api

I hope this is helpful!