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

Forums / Developing with Sitefinity / Library Selector

Library Selector

17 posts, 0 answered
  1. Dale Palmer
    Dale Palmer avatar
    20 posts
    Registered:
    12 May 2008
    20 Mar 2009
    Link to this post
    I am writing a new usercontrol which i want to allow the user to select an associated Image Library for the user control but when it comes to selecting the library i get the following error. Here is my property for the usercontrol

    Unable to cast object of type 'System.Guid' to type 'System.Guid[]'.

     

        private Guid _libID;  
          
        [TypeConverter("Telerik.Cms.Web.UI.GuidTypeConverter, Telerik.Cms")]  
        [Telerik.Cms.Web.UI.WebEditor("Telerik.Libraries.WebControls.LibrarySelector, Telerik.Libraries")]  
        [DefaultValue(typeof(Guid), "00000000-0000-0000-0000-000000000000")]  
            public Guid LibraryId  
            {  
                get  
                {  
                    return _libID;  
                }  
                set  
                {  
                    _libID = value;  
                }  
            } 

    This is the only thing stopping us from finalizing a project. Could someone from Telerik PLEASE RESPOND ASAP because your documentation is poor when it comes to Selectors and let me know how to fix this.

    please dont tell me this is going to be fixed in version 4 because we are using 3.5!

    Image of error : http://www.grow-studio.com/ERROR.jpg
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    23 Mar 2009
    Link to this post
    Hello Dale Palmer,

    I saw that my colleague Pepi has sent a reply to you. Please reply to the ticket in case of any problems.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Tobias
    Tobias avatar
    11 posts
    Registered:
    02 Mar 2009
    09 Apr 2009
    Link to this post
    Hello Ivan,

    i need a solution for this problem, also.
    Can you please post it here?
    or
    Maybe there is an other solution to select an library in my own usercontrol. Please
    show me the best way.

    Thanks in advance
    Tobias
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    09 Apr 2009
    Link to this post
    Hi Tobias,

    The problem here is that LibrarySelector is a base class. It cannot be used directly. The solution is creating custom selector extending from LibrarySelector and override CreateChildControls method.

        private Guid[] _libID;  
      
    [TypeConverter("Telerik.Framework.Utilities.GuidArrayConverter, Telerik.Framework")]  
    [Telerik.Cms.Web.UI.WebEditor("Telerik.Libraries.WebControls.MyLibrarySelector, App_Code")]  
        public Guid[] LibraryId  
        {  
            get  
            {  
                return _libID;  
            }  
            set  
            {  
                _libID = value;  
            }  
        }  


    Here is a sample custom selector

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using Telerik.Libraries.Resources;  
    using System.Web.UI.WebControls;  
      
    namespace Telerik.Libraries.WebControls  
    {  
        public class MyLibrarySelector : LibrarySelector  
        {  
            
            protected override void CreateChildControls()  
            {  
                base.SelectAllItemsText = "Select All";  
                base.SelectSpecificItemsText = "Select Specific Library";  
      
                base.TypeName = "Telerik.Libraries.LibraryManager";  
                base.SelectedMethod = "GetAllLibraries";  
      
                base.CreateChildControls();  
            }   
        }  
    }  


    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Tobias
    Tobias avatar
    11 posts
    Registered:
    02 Mar 2009
    10 Apr 2009
    Link to this post
    Hi Ivan,

    thanks you for your quick response and the great sample.

    Greetings
    Tobias
  6. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    15 May 2009
    Link to this post
    Hi Ivan,

    I have still not fixed my Library Selector and this looks like an interesting post. Where exactly in the filing system do you put the MyLibrarySelector class? Do I just copy the class in there as it is? 

    Thank you


  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    15 May 2009
    Link to this post
    Hi Andrei,

    "MyLibrarySelector" is a custom selector. It is a class that I have added in App_Code folder. Then in my user control code behind I am calling this selector from App_Code, with its namespace.
    You can gathermore information about custom web editors from sitefinitywatch.com

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. batFINGER
    batFINGER avatar
    8 posts
    Registered:
    26 Aug 2009
    08 Sep 2009
    Link to this post
    Greetings,

    Have used your method to asscociate image libs with the homegallery control from the TIU site. Here is the code

    homegallery.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="HomeGallery.ascx.cs" Inherits="UserControls_HomeGallery" %> 
    <div class="Rotator">  
        <telerik:RadRotator runat="server" ID="RadRotator1" Width="270" Height="310">  
            <ItemTemplate> 
                <asp:Image CssClass="RotatorFrame" runat="server" ID="rotatorIMG" Width="270" /> 
            </ItemTemplate> 
        </telerik:RadRotator> 
        <div class="RotatorControl">  
            <href="#" onclick="($find('<%= RadRotator1.ClientID %>')).showNext(Telerik.Web.UI.RotatorScrollDirection.Right);return false;" 
                class="RotatorPrev">Previous</a> <href="#" onclick="($find('<%= RadRotator1.ClientID %>')).pause();  
                                    this.style.display = 'none';  
                                    document.getElementById('<%= RadRotator1.ClientID %>Start').style.display='block';  
                                    return false;" class="RotatorStop" id="<%= RadRotator1.ClientID %>Stop">  
                    Stop</a> <href="#" onclick="($find('<%= RadRotator1.ClientID %>')).resume();  
                                    this.style.display = 'none';          
                                    document.getElementById('<%= RadRotator1.ClientID %>Stop').style.display='block';return false;"  
                        class="RotatorStart" id="<%= RadRotator1.ClientID %>Start">Start</a> 
            <href="#" onclick="($find('<%= RadRotator1.ClientID %>')).showNext(Telerik.Web.UI.RotatorScrollDirection.Left);return false;" 
                class="RotatorNext">Next</a> <href="~/AboutUs/Gallery.aspx" runat="server" class="ViewGallery">  
                    View Gallery</a> 
        </div> 
    </div> 
    .aspx.cs
    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Collections;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Web.UI.HtmlControls;  
    using Telerik.Libraries;  
    using Telerik.Web.UI;  
    using Telerik.News;  
    using Telerik.Cms.Engine;  
    using Telerik.Cms.Web.UI;  
    using System.ComponentModel;  
     
     
    public partial class UserControls_HomeGallery : System.Web.UI.UserControl  
    {  
        private LibraryManager manager;  
        private string _LibraryName = "Panoramas";  
        private Guid[] _LibraryID;  
     
        public string LibraryName  
          
        {  
            get { return _LibraryName; }  
            set { _LibraryName = value; }  
        }  
        [TypeConverter("Telerik.Framework.Utilities.GuidArrayConverter, Telerik.Framework")]    
     
        [Telerik.Cms.Web.UI.WebEditor("Telerik.Libraries.WebControls.MyLibrarySelector, App_Code")]    
        public Guid[] LibraryID  
        {  
            get { return _LibraryID; }  
            set { _LibraryID = value; }  
        }  
          
        protected void Page_Load(object sender, EventArgs e)  
        {  
            IList images = null;  
              
            if (this.manager == null)  
                this.manager = new LibraryManager();  
            ILibrary library = this.manager.GetLibrary(LibraryID[0]);//this.manager.GetLibrary(LibraryName);  
              
            if (library != null)  
            {  
                images = library.GetItems();  
                  
            }  
            RadRotator1.DataSource = images;  
            this.RadRotator1.ItemDataBound += new RadRotatorEventHandler(ItemDataBound);   
            RadRotator1.DataBind();  
     
        }  
        void ItemDataBound(object sender, RadRotatorEventArgs e)  
        {  
            //IList cnt = (IList)e.Item.DataItem;  
            IContent cnt = e.Item.DataItem as IContent;  
            if (cnt != null)  
            {  
     
                Image img = e.Item.FindControl("rotatorIMG"as Image;  
                if (img != null)  
                    img.ImageUrl = cnt.UrlWithExtension;  
            }  
        }    
     
    }  
     

    The css can be found at your TIU site, the MyLibrarySelector class in App_Code as explained.

    This works Ok, but is there a way to  Filter to Only select image galleries, by name rather than GUID[]
    and can this be done with the GallerySelector class and if so how.

    Cheers.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Sep 2009
    Link to this post
    Hi batFINGER,

    You can use manager.GetLibrary(Name). The code exposes a public property _LibraryName.
    However I developed a custom WebEditor that you can add to this property and select from the available Libraries.

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using Telerik.Cms.Web.UI; 
    using Telerik.Web.UI; 
    using Telerik.Framework.Web; 
    using System.Web.UI; 
    using Telerik.Libraries; 
    using System.Collections; 
     
    /// <summary> 
    /// Summary description for LibraryNameSelector 
    /// </summary> 
     
    public class LibraryNameSelector : WebUITypeEditor<string
        public LibraryNameSelector() 
        { 
        } 
     
        public override string Value 
        { 
            get 
            { 
                object o = this.ViewState["CatName"]; 
                if (o == null
                    return string.Empty; 
                return (string)o; 
     
            } 
            set 
            { 
                this.ViewState["CatName"] = value; 
            } 
        } 
        public string TemplatePath 
        { 
            get 
            { 
                object o = this.ViewState["templatePath"]; 
                if (o == null
                    return "~/CustomControls/WebUserControl.ascx"
                return (string)o; 
            } 
            set 
            { 
                this.ViewState["templatePath"] = value; 
     
            } 
        } 
     
        protected virtual RadComboBox combo 
        { 
            get { return this.Controls[0].FindControl("RadCombo"as RadComboBox; } 
        } 
     
        protected override void CreateChildControls() 
        { 
            this.dialogTemplate = ControlUtils.GetTemplate<DialogTemplate>(this.TemplatePath); 
            this.dialogTemplate.InstantiateIn(this); 
            LibraryManager manager = new LibraryManager("Libraries"); 
            IList allLibraries = manager.GetAllLibraries(); 
            combo.DataSource = allLibraries; 
            combo.DataTextField = "Name"
            combo.DataBind(); 
            this.Value = combo.SelectedItem.Text; 
             
        } 
     
        public ITemplate DialogTemplatePath 
        { 
            get 
            { 
                dialogTemplate = ControlUtils.GetTemplate<DialogTemplate>(this.TemplatePath); 
                return dialogTemplate; 
            } 
            set 
            { 
                dialogTemplate = value; 
            } 
        } 
        private ITemplate dialogTemplate; 
     
     
        private class DialogTemplate : ITemplate 
        { 
            public void InstantiateIn(Control container) 
            { 
                throw new Exception("Default template  has not been implemented."); 
            } 
        } 
     

    Declare RadComboBox in the template.

    <telerik:RadComboBox ID="RadCombo" runat="server" /> 


    Sincerely yours,
    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.
  10. batFINGER
    batFINGER avatar
    8 posts
    Registered:
    26 Aug 2009
    09 Sep 2009
    Link to this post
    Thankyou.

    That was exactly what I was looking for. I have a problem though, the radcombobox is disabled on the dialog control. The databinding worked, you can see the libs when using the arrows on keyboard. 

    Haven't used the combobox before, Do i need to skin it or something. 
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    09 Sep 2009
    Link to this post
    Hello batFINGER,

    Generally it is not necessary to style the combo. If you like to do it It will be simple because you have the control declaration in our CustomControl template. You can gather more information about RadComboBox at Controlling RadComboBox appearance.

    Greetings,
    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.
  12. batFINGER
    batFINGER avatar
    8 posts
    Registered:
    26 Aug 2009
    09 Sep 2009
    Link to this post
    Ivan,

    Still No Joy with radcombobox on the "Library Name" dialog. Got comboboxes working on site ok.

    combo renders and selects current library, but there is no functionality, it appears disabled. Same with hardcoded comboboxes in the webcontrol.

    Only change to previous code 
        private string _LibraryName = "Panoramas"
        private Guid[] _LibraryID; 
     
        [Telerik.Cms.Web.UI.WebEditor("LibraryNameSelector, App_Code")]   
        public string LibraryName 
        { 
            get { return _LibraryName; } 
            set { _LibraryName = value; } 
        } 

    webcontrol.aspx

    <%@ Control Language="c#" AutoEventWireup="false" %> 
     
    <asp:Panel ID="holderPanel" runat="server" > 
        <telerik:RadComboBox ID="RadCombo" Skin="Black" runat="server" Height="100px" > 
     
        </telerik:RadComboBox> 
     
        <telerik:radcombobox id="RadComboBox1" runat="server" height="90px"  
            width="150px" skin="Telerik" 
            showtoggleimage="True" AppendDataBoundItems="True"
               <Items> 
                  <telerik:RadComboBoxItem 
                        ImagePath="e" 
                        DisplayName="RadEditor" 
                        Text="RadEditor"
                  </telerik:RadComboBoxItem> 
                  <telerik:RadComboBoxItem 
                        ImagePath="t" 
                        DisplayName="RadTreeView" 
                        Text="RadTreeView"
                  </telerik:RadComboBoxItem> 
                  <telerik:RadComboBoxItem 
                        ImagePath="s" 
                        DisplayName="RadSpell" 
                        Text="RadSpell"
                  </telerik:RadComboBoxItem> 
                  <telerik:RadComboBoxItem 
                        ImagePath="m" 
                        DisplayName="RadMenu" 
                        Text="RadMenu"
                  </telerik:RadComboBoxItem> 
                  <telerik:RadComboBoxItem 
                        ImagePath="tab" 
                        DisplayName="RadTabstrip" 
                        Text="RadTabstrip"
                  </telerik:RadComboBoxItem> 
               </Items> 
    </telerik:radcombobox> 
    </asp:Panel> 

    Both combos are disabled when the library selector dialog. Got me stumped. They work everywhere else i put them. Reckon it's prob something simple but it is annoying the s...
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Sep 2009
    Link to this post
    Hi batFINGER,

    Try replacing the RadComboBox with DropDownList. It seems that there is a problem with the combo and RadWindow and I need to observe this further.

    Below is the code you should replace

     protected virtual DropDownList combo 
        { 
            get { return this.Controls[0].FindControl("RadCombo"as DropDownList; } 
        } 
     
        protected override void CreateChildControls() 
        { 
            this.dialogTemplate = ControlUtils.GetTemplate<DialogTemplate>(this.TemplatePath); 
            this.dialogTemplate.InstantiateIn(this); 
            LibraryManager manager = new LibraryManager("Libraries"); 
            IList allLibraries = manager.GetAllLibraries(); 
            combo.DataSource = allLibraries; 
            combo.DataTextField = "Name"
            combo.DataBind();      
            combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged);  
             
        } 
     
        void combo_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            this.Value = combo.SelectedItem.Text; 
        } 
     

    All the best,
    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.
  14. batFINGER
    batFINGER avatar
    8 posts
    Registered:
    26 Aug 2009
    10 Sep 2009
    Link to this post
    Thanks Ivan,

    There is a post in telerik  community forums, wondered whether this was linked in some way. 

    DataBinding a RadCombobox in an ItemTemplate


    Once again thankyou for your help.



  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Sep 2009
    Link to this post
    Hi batFINGER,

    Yes, but the post is related to binding RAdComboBox inside RadGrid's GridTemplateColumn. We are loading the RadTreeView in completely different environment. 

    All the best,
    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.
  16. Ahmed Salman
    Ahmed Salman avatar
    31 posts
    Registered:
    13 Apr 2010
    13 Jul 2010
    Link to this post
    where i should but this code ?? which template ??  i am lost


    Declare RadComboBox in the template.

    <telerik:RadComboBox ID="RadCombo" runat="server" /> 
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Jul 2010
    Link to this post
    Hello Ahmed Salman,

    The path of WebUITypeEditor template is set through TemplatePath property. You can see it in the code above. Inside this template (ascx) file you need to declare RadComboBox control.

    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
Register for webinar
17 posts, 0 answered