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

Forums / General Discussions / Image Gallery Search

Image Gallery Search

10 posts, 0 answered
  1. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    05 Oct 2009
    Link to this post
    Is it possible to create my own search control which searches photos in particular image libraries? Thanks in advanced.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    05 Oct 2009
    Link to this post
    Hello Developer,

    It is possible. You need to get a list of all items and pass the parentID - the id of a library. Sample code:

    LibraryManager libraryManager = new LibraryManager("Libraries"); 
    ILibrary parent = manager.GetLibrary(new Guid("82FCEB5A-84D9-481d-BF34-6EB82680F609"); 
    IList items = libraryManager.GetContent(0, 10, string.Empty, parent.ID) 
     

    I hope this helps.

    Best wishes,
    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.
  3. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    05 Oct 2009
    Link to this post
    Then how can I loop through the items to get title and path of each image?
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    06 Oct 2009
    Link to this post
    Hi Developer,

    You can take a look at the examples in our on-line help. Take a look at this article: Managing Files with LibraryManager. There you can take a look at the second example to see how to loop through all images in library (using foreach loop) and get image names. You can get image patsh if you use:
    string path = contentItem.UrlWithExtension(); 

    in the same foreach loop.
     
    Greetings,
    Radoslav Georgiev
    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.
  5. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    06 Oct 2009
    Link to this post
    Is it possible to do index search on a particular library? If yes, how can I make the control? Thanks.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    06 Oct 2009
    Link to this post
    Hi Developer,

    You need to create a custom indexing provider that inherits from ContentIndexProvider. In your custom provider override ParentIDs and set the ID of a library. Below is a sample implementation of the provider.

    Sample code:

    using System; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Globalization; 
    using System.Text; 
    using Telerik.Cms.Engine; 
    using Telerik.Framework.Search; 
    using Telerik.Libraries; 
     
    namespace Telerik.Sample 
     
        public class LibraryIndexingProvider : ContentIndexProvider 
        { 
     
            public override string Name 
            { 
                get { return "LibraryIndesingProvider"; } 
            } 
     
            public override string Description 
            { 
                get { return "Some Description goes here"; } 
            } 
     
     
            protected override string ContentItemKeyImpl 
            { 
                get 
                { 
                    return LibraryManager.ContentItemKey; 
                } 
            } 
     
            protected override string ContentProviderKeyImpl 
            { 
                get 
                { 
                    return LibraryManager.ContentProviderKey; 
                } 
            } 
     
     
            protected override string GetDefaultContentProvider() 
            { 
                return LibraryManager.DefaultContentProvider; 
            } 
     
     
            public override string FilterExpression 
            { 
                get 
                { 
                    return ""
                } 
            } 
     
     
            public override IDictionary<stringstring> AdditionalFields 
            { 
                get 
                { 
                    if (this.ILibImpl != null
                    { 
                        IDictionary<stringstring> tempDict; 
                        tempDict = new Dictionary<stringstring>(); 
                        tempDict.Add("Author"
                            !string.IsNullOrEmpty(ILibImpl.Name) ? ILibImpl.Name : string.Empty); 
                        return tempDict; 
                    } 
     
                    return base.AdditionalFields; 
                } 
            } 
     
            
            protected override string GetItemUrl(IContent contentItem, string singleItemUrl, CultureInfo culture) 
            { 
                if (String.IsNullOrEmpty(singleItemUrl)) 
                { 
                    ILibrary library = this.GetLib(contentItem); 
                   // FORMAT THE URL FROM library.Name and contentItem.UrlWithExtenssion or  
                   // contentItem.ThumbnailUrl 
                } 
                return base.GetItemUrl(contentItem, singleItemUrl, culture); 
            } 
     
            private ILibrary GetLib(IContent item) 
            { 
                if (this.ILibImpl != null && this.ILibImpl.ID == item.ParentID) 
                    return this.ILibImpl; 
     
                ILibraryProvider provider = (ILibraryProvider)base.Manager.Provider; 
                this.ILibImpl = provider.GetLibrary(item.ParentID); 
                if (this.ILibImpl == null
                    throw new ArgumentException("Invalid Lib ID"); 
                return this.ILibImpl; 
            } 
     
            private ILibrary ILibImpl; 
     
            //OR OVERRIDE PARENTIDs 
            public override Guid[] ParentIDs 
            { 
                get 
                { 
                    return new Guid[] { new Guid("B1403376-B328-4c5d-BCD0-23C225BB01DD") }; 
                } 
            } 
     
        } 


    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.
  7. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    06 Oct 2009
    Link to this post
    I am very new to Sitefinity, so can you tell me how to override the ParentIDs and set the ID of a library in your custom provider?

    I read an article (example on Ivan's Blog) and noticed that there is an override method Initialize which you did not implement in your simple code. Do I have to implement it? Also, how to implement a LibraryIndexSetting control so that end users can pick up any library when they create image search index?

    Thank you in advance!
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Oct 2009
    Link to this post
    Hello Developer,

    You can override Initialize method. For your LibrarySettingsControl you need to create a template that will have a repeater or RadComboBox bound to a list of all Libraries. You can use  IList list = provider.GetAllLibraries();
    Then when a Library is selected from the list you need to pass its ID to the LibraryIndexingProvider by overriding GetSettings().

    sample

    public IDictionary<stringstring> GetSettings() 
            { 
                settings = new Dictionary<stringstring>(); 
                settings["LibraryIndexingProvider"] = ProviderName = this.DropDownList.SelectedValue; 
                // do something else 
                return settings; 
            } 


    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.
  9. Stephen
    Stephen avatar
    70 posts
    Registered:
    09 Jun 2009
    07 Oct 2009
    Link to this post
    Can you provide me some sample code:
    1) how to override Initialize method
    2) how to create a template to a lst of libraries for my LibrarySettingControl

    Thanks.

    My code for ImageSearchIndexSettingsControl (LibrarySettingControl)
    public class ImageSearchIndexSettingsControl : CompositeControl, ISettingsControl 
        { 
            #region Properties 
     
            /// <summary> 
            /// Gets or sets the Control Template path 
            /// </summary> 
            public string ControlTemplatePath 
            { 
                get 
                { 
                    object o = ViewState["ControlTemplatePath"]; 
                    if (o == null) 
                        return "~/Sitefinity/Admin/ControlTemplates/ImageSearch/ImageSearchIndexSettingsControl.ascx"; 
                    return (string)o; 
                } 
                set 
                { 
                    ViewState["ControlTemplatePath"] = value; 
                } 
            } 
     
            /// <summary> 
            /// Gets or sets the control template 
            /// </summary> 
            public ITemplate ControlTemplate 
            { 
                get 
                { 
                    if (controlTemplate == null) 
                        controlTemplate = ControlUtils.GetTemplate<DefaultTemplate>(ControlTemplatePath); 
                    return controlTemplate; 
                } 
                set 
                { 
                    controlTemplate = value
                } 
            } 
     
            /// <summary> 
            /// Gets or Sets the name of the provider 
            /// </summary> 
            public string ProviderName 
            { 
                get 
                { 
                    object o = ViewState["ProviderName"]; 
                    if (o == null) 
                        return String.Empty; 
                    return (string)o; 
                } 
                set 
                { 
                    ViewState["ProviderName"] = value; 
                } 
            } 
     
     
            /// <summary> 
            /// Gets or Sets the page Url for displaying the news item 
            /// </summary> 
            public string SingleProductUrl 
            { 
                get 
                { 
                    if (ctrlContainer.SingleProductUrl != null) 
                        return ctrlContainer.SingleProductUrl.Text; 
                    return string.Empty; 
                } 
                set 
                { 
                    ctrlContainer.SingleProductUrl.Text = value
                } 
            } 
            #endregion 
     
            #region Inherited Methods 
     
            /// <summary> 
            /// Overriden. Cancels the rendering of a beginning HTML tag for the control. 
            /// </summary> 
            /// <param name="writer">The HtmlTextWriter object used to render the markup.</param> 
            public override void RenderBeginTag(HtmlTextWriter writer) 
            { 
            } 
     
            /// <summary> 
            /// Overriden. Cancels the rendering of an ending HTML tag for the control. 
            /// </summary> 
            /// <param name="writer">The HtmlTextWriter object used to render the markup.</param> 
            public override void RenderEndTag(HtmlTextWriter writer) 
            { 
            } 
     
            /// <summary> 
            /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation 
            /// to create any child controls they contain in preparation for posting back or rendering. 
            /// </summary> 
            protected override void CreateChildControls() 
            { 
                ctrlContainer = new ControlContainer(this); 
                ControlTemplate.InstantiateIn(ctrlContainer); 
     
                properties = TypeDescriptor.GetProperties(this); 
                PropertyDescriptor desc = properties.Find("SingleProductUrl", false); 
     
                editorDialog = new PropertyEditorDialog(); 
                editorDialog.TypeContainer = this
                editorDialog.PropertyChanged += editorDialog_PropertyChanged; 
                Controls.Add(editorDialog); 
     
                string[] provNames = null
                int count = ConfigHelper.Handler.GenericContentProviders.Count; 
                if (count > 1) 
                { 
                    int i = 0
                    provNames = new string[count]; 
                    foreach (GenericContentElement element in ConfigHelper.Handler.GenericContentProviders) 
                    { 
                        GlobalPermission perm = new GlobalPermission( 
                            (GlobalPermissions)ImageSearchManager.SecurityRoots[element.ProviderName], CrudRights.View); 
                        if (perm.CheckDemand()) 
                        { 
                            provNames[i++] = element.ProviderName; 
                        } 
                    } 
                } 
     
                ListControl list = ctrlContainer.ProviderName; 
                if (provNames != null) 
                { 
                    foreach (string name in provNames) 
                    { 
                        if (!String.IsNullOrEmpty(name)) 
                        { 
                            ListItem item = new ListItem(name.Replace('_', ' '), name); 
                            list.Items.Add(item); 
                        } 
                    } 
                } 
                ctrlContainer.ProviderNameLi.Visible = (list.Items.Count > 1); 
     
                ctrlContainer.SelectProductUrl.CommandName = "Telerik.Cms.Web.UI.PageIndexUrlWebEditor, Telerik.Cms"
                ctrlContainer.SelectProductUrl.CommandArgument = desc.Name; 
                ctrlContainer.SelectProductUrl.Command += SelectSingleProductUrl_Command; 
                ctrlContainer.ProviderName.SelectedIndexChanged += ProviderName_SelectedIndexChanged; 
     
                if (settings != null && settings.Count > 0) 
                { 
                    ctrlContainer.ProviderName.SelectedValue = ProviderName = settings["ImageSearchIndexProvider"]; 
                    ctrlContainer.SingleProductUrl.Text = settings["ImageSearchPageUrl"]; 
                } 
     
                Controls.Add(ctrlContainer); 
            } 
     
            void ProviderName_SelectedIndexChanged(object sender, EventArgs e) 
            { 
                ProviderName = ((ListControl)sender).SelectedValue; 
            } 
     
            void SelectSingleProductUrl_Command(object sender, CommandEventArgs e) 
            { 
                object data; 
                string name = (string)e.CommandArgument; 
     
                PropertyDescriptor desc = properties.Find(name, false); 
                data = desc.Converter.ConvertToInvariantString(this); 
     
                editorDialog.Show(name, e.CommandName, data, this); 
            } 
     
            void editorDialog_PropertyChanged(object source, PropertyValueChangedEventArgs e) 
            { 
                string[] resultValue = ((string)e.PropertyValue).Split(';'); 
                SetProperty(this, properties, e.PropertyName, resultValue[1]); 
            } 
     
            private void SetProperty(object component, PropertyDescriptorCollection _properties, string name, object value) 
            { 
                PropertyDescriptor desc = _properties.Find(name, false); 
                desc.SetValue(component, value); 
            } 
     
            /// <summary> 
            /// It initializes the _settings. 
            /// </summary> 
            /// <param name="_settings"
            ///   The parameter contains the default values when a new provider is created (in IRssProviderModule implementation) 
            ///   If the provider has already been created, the parameter contains the values saved in the database. 
            /// </param> 
            public void InitSettings(IDictionary<string, string> _settings) 
            { 
                settings = _settings
            } 
     
            /// <summary> 
            /// Gets the newly edited settings. 
            /// </summary> 
            /// <returns> an object of type Dictionary that contains strings</returns> 
            public IDictionary<string, string> GetSettings() 
            { 
                settings = new Dictionary<string, string>(); 
                settings["ImageSearchIndexProvider"] = ProviderName = ctrlContainer.ProviderName.SelectedValue; 
                settings["ImageSearchPageUrl"] = ctrlContainer.SingleProductUrl.Text; 
                return settings; 
            } 
     
            #endregion 
     
            #region Private Fields 
     
            private PropertyDescriptorCollection properties; 
            private ITemplate controlTemplate; 
            private ControlContainer ctrlContainer; 
            private IDictionary<string, string> settings; 
            private PropertyEditorDialog editorDialog; 
     
            #endregion 
     
            #region DefaultTemplate 
     
            /// <summary> 
            /// The default template class 
            /// </summary> 
            protected class DefaultTemplate : ITemplate 
            { 
                /// <summary> 
                /// Instantiates the specified control in the default template 
                /// </summary> 
                /// <param name="container">accepts a parameter of type Control</param> 
                public void InstantiateIn(Control container) 
                { 
     
                } 
            } 
     
            #endregion 
     
            #region Container 
     
            /// <summary> 
            /// The control container class 
            /// </summary> 
            protected class ControlContainer : GenericContainer<ImageSearchIndexSettingsControl> 
            { 
                /// <summary> 
                /// Constructs the control container 
                /// </summary> 
                /// <param name="owner">accepts a parameter of type RssSettingsControl</param> 
                public ControlContainer(ImageSearchIndexSettingsControl owner) 
                    : base(owner) 
                { 
                } 
     
                /// <summary> 
                /// Gets the control which displays the Provider Name. 
                /// </summary> 
                public ListControl ProviderName 
                { 
                    get 
                    { 
                        if (providerName == null) 
                            providerName = FindRequiredControl<ListControl>("imageSearchProvider"); 
                        return providerName; 
                    } 
                } 
     
                /// <summary> 
                /// Gets the control which displays the single product url which could be edited. 
                /// </summary> 
                public IEditableTextControl SingleProductUrl 
                { 
                    get 
                    { 
                        if (singleProductUrl == null) 
                            singleProductUrl = (IEditableTextControl)FindControl(typeof(IEditableTextControl), "singleProductUrl", true); 
                        return singleProductUrl; 
                    } 
                } 
     
     
                /// <summary> 
                /// Gets the control which displays the post url in a link button which could be selected. 
                /// </summary> 
                public IButtonControl SelectProductUrl 
                { 
                    get 
                    { 
                        if (selectProductUrl == null) 
                            selectProductUrl = (IButtonControl)FindControl(typeof(IButtonControl), "selectSingleProductUrl", true); 
                        return selectProductUrl; 
                    } 
                } 
     
                /// <summary> 
                /// Gets the control which displays the "li" tag with information about the Provider Name 
                /// </summary> 
                public HtmlGenericControl ProviderNameLi 
                { 
                    get 
                    { 
                        if (providerNameLi == null) 
                            providerNameLi = FindRequiredControl<HtmlGenericControl>("providerNameLi"); 
                        return providerNameLi; 
                    } 
                } 
     
                private HtmlGenericControl providerNameLi; 
                private IButtonControl selectProductUrl; 
                private ListControl providerName; 
                private IEditableTextControl singleProductUrl; 
            } 
     
            #endregion 
        } 


  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Oct 2009
    Link to this post
    Hi Developer,

    The code you have is not correct for your case.

    1. You need to pass the parent ID - the Library which you are going to index
    2. Your template should contain

    - Textbox and DropDownList or Library selector bounded to list of all Libraries items. You will pass the library ID to the textbox and then to LibraryIndexingProvider  as suggested in the previous post. Currently you have copy pased the provider from Products module but it does not support this functionallity. You need to use GetLib(IConent item) method from the sample I sent you to return the library ID.

    Best wishes,
    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.
Register for webinar
10 posts, 0 answered