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

Forums / Developing with Sitefinity / Custom Library Content provider and sitefinity interfaces

Custom Library Content provider and sitefinity interfaces

2 posts, 0 answered
  1. Lucas
    Lucas avatar
    65 posts
    Registered:
    22 Mar 2010
    15 Sep 2010
    Link to this post
    Hello,

    I have created a custom provider for libraries deriving from Telerik.Libraries.Data.DefaultProvider.

    The aim was to hide some libraries that are not supposed to be selected manually.
    I have overriden the two GetAllLibraries functions, and GetLibrariesCountOptimized, and left the rest alone:

    public class DocumentProvider : Telerik.Libraries.Data.DefaultProvider
    {
        public override System.Collections.IList GetAllLibraries(string typeName, bool isEqual)
        {
            // stuff hiding a specific libraryType if isEqual == false
        }
        public override System.Collections.IList GetAllLibraries(int from, int max, ref int count, string sortExp)
        {
            // stuff hiding a specific libraryType
        }
     
        protected override int GetLibrariesCountOptimized()
        {
            //stuff hiding a specific LibraryType
        }
    }

    (code omitted for clarity).
    I have defined my provider in the web.config:
    <libraries defaultGenericProvider="Libraries">
        <genericContentProviders>
            <add providerName="Libraries" publicationDateField="Publication_Date"/>
            <add providerName="LibrariesWithoutPages" publicationDateField="Publication_Date"/>
    (...)
     
    and
     
    <cmsEngine defaultProvider="Generic_Content">
        <providers>
            <clear/>
            <add name="Libraries" urlRewriteFormat="~/{Provider}/{LibraryName}/[Name].sflb.ashx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" applicationName="/Libraries" allowVersioning="False" allowLocalization="False" localizationProviderName="" allowWorkflow="False" securityProviderName="" versioningProviderName="" connectionStringName="GenericContentConnection" type="Telerik.Libraries.Data.DefaultProvider, Telerik.Libraries.Data" tagEditorTemplate="~/Sitefinity/Admin/ControlTemplates/Libraries/BatchTagsEditor.ascx"/>
            <add name="LibrariesWithoutPages" urlRewriteFormat="~/{Provider}/{LibraryName}/[Name].sflb.ashx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" applicationName="/Libraries" allowVersioning="False" allowLocalization="False" localizationProviderName="" allowWorkflow="False" securityProviderName="" versioningProviderName="" connectionStringName="GenericContentConnection" type="TAD.Sitefinity.Controls.Documents.Provider.DocumentProvider, TAD.Sitefinity.Controls.Documents" tagEditorTemplate="~/Sitefinity/Admin/ControlTemplates/Libraries/BatchTagsEditor.ascx"/>



    I have modified ImageDialog.aspx in order to specify this provider:
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <%--
        /// <summary>
        /// Note: File modified from the original Sitefinity Installation
        /// </summary> --%>
    <lib:ItemSelector runat="server" AllowPageSelection="false" ProviderName="LibrariesWithoutPages" ShowMode="Images" />
    </form>


    Strangely, when I try to select an image, the library list works as expected (cf screenshot, there's a few hidden libraries) but when I select a library, the site crashes:
    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Libraries.WebControls.ItemSelector.ItemsRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e) +599
       System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +108
       System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +136
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +443
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +51
       System.Web.UI.WebControls.Repeater.DataBind() +75
       Telerik.Libraries.WebControls.ItemSelector.CreateItemsView() +2031
       Telerik.Libraries.WebControls.ItemSelector.CreateChildControls() +361
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

    I have set breakpoints in the provider, and the call to GetImages(int from, int max, string sortExp, string tagName, Guid[] parentIDs, Telerik.Cms.Engine.IMetaSearchInfo[] filter) returns content (50 items)

    Any idea? :/
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Sep 2010
    Link to this post
    Hello Lucas,

    The error is thrown, because you have not added metakyes for your custom provider in the web.config

    <add key="LibrariesWithoutPages.Name" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Width" valueType="Integer" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Height" valueType="Integer" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Size" valueType="Integer" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Extension" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.AlternateText" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Author" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Description" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.Category" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>
            <add key="LibrariesWithoutPages.PermaLink" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>


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