Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sune Jepsen 25 posts 109 karma points
    Jan 13, 2011 @ 22:36
    Sune Jepsen
    0

    universal media picker provider

    Following up on my previous question http://our.umbraco.org/forum/developers/extending-umbraco/16243-Pick-from-custom-section, on how to pick from a custom tree section, Matt Brailsford suggested to use the universal media picker. Ive now tried to create my own provider to the universal media picker. Ive created my class library project:

    public class CustomSectionProvider : AbstractProvider
        {
            private static ISqlHelper sqlHelper;

            public CustomSectionProvider()
            {
                sqlHelper = DataLayerHelper.CreateSqlHelper(@"server=.\sqlexpress;database=Northwind;user id=sj;password=123qweasdzxc");
     
            }

              public CustomSectionProvider(string config)
                : base(config)
            {
            }
            public override string Alias
            {
                get { return "Shopproducts"; }
            }

            public override Interfaces.IConfigControl ConfigControl
            {
                get { throw new NotImplementedException(); }
            }

            public override Interfaces.ICreateControl CreateControl
            {
                get { throw new NotImplementedException(); }
            }

            public override MediaItem GetMediaItemById(string id)
            {
                var reader = sqlHelper.ExecuteReader(@"SELECT ProductID, ProductName FROM Products WHERE ProductID="+int.Parse(id));
                var mediaItem = new MediaItem();
                if (reader.Read())
                {

                    mediaItem.Id = reader.Get<int>("ProductID").ToString();
                    mediaItem.Title = reader.Get<string>("ProductName").ToString();
                    mediaItem.Icon = UmbracoIcons.FolderOpen;
                    mediaItem.HasChildren = false;
                    mediaItem.PreviewImageUrl = "";
                    mediaItem.Selectable = false;

                }
                return mediaItem;

            }

            public override IList<MediaItem> GetMediaItems(string parentId)
            {
                var reader = sqlHelper.ExecuteReader(@"SELECT ProductID, ProductName FROM Products");
                var mediaItems = new List<MediaItem>();

                while (reader.Read())
                {

                    mediaItems.Add(new MediaItem
                    {
                        Id = reader.Get<int>("ProductID").ToString(),
                        Title =reader.Get<string>("ProductName").ToString(),
                        Icon = UmbracoIcons.FolderOpen,
                        HasChildren = false,
                        PreviewImageUrl = "",
                        Selectable = false
                    });
     
                }
                return mediaItems;
            }
        }

     

    How and what do I, add it to the provider list when I install the universal media picker package. ?? 

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 14, 2011 @ 09:31
    Matt Brailsford
    0

    Hey,

    If you install the main Universal Media Picker package, then just drop your DLL in the bin folder, the Universal Media Picker will automatically discover any classes that implement the IProvider interface (which AbstractProvider implements) and automatically add them to the Provider dropdown list.

    All the best

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft