sitefinity从模块获取文档

时间:2013-01-17 11:32:02

标签: sitefinity sitefinity-4

我想在此模块中使用Pdf字段。我想达到pdf完整网址和名称,但不知道如何做sitefinity。有人可以帮帮我吗?

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 个答案:

答案 0 :(得分:0)

你肯定是在正确的轨道上! ContentLink []是媒体的存储方式,因为它实际上存储了对库项目的引用。

您只需将ChildItemId从内容链接(c1.ChildItemId)传递到LibraryManager.Get方法(如GetImage或GetDocument)即可获取实际内容项。

从那里你可以简单地做Content.Url来获得库项目的实际链接。

这里有一个关于Sitefinity博客的例子:http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2012/01/19/retrieving_data_from_dynamic_modules_using_the_module_builder_api

我希望这有用!