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()) {
public override IList<MediaItem> GetMediaItems(string parentId) { var reader = sqlHelper.ExecuteReader(@"SELECT ProductID, ProductName FROM Products"); var mediaItems = new List<MediaItem>();
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.
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. ??
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
is working on a reply...