Im trying to add the improved mediapicker to my custom section.
I whant to add it by code so that im able to select a image and work with the image id. But i cant get it up and running. I have downloaded the Nibble dll file and added it as a reference in VS. I also uploaded the dll to the umbraco bin folder. Where should i put the other files?(aspx files and webservices).
Is this the correct way to implement the improved mediapicker or am I missing something?
The code compiles but i get and error saying when i run it:
[HttpException (0x80004005): Request is not available in this context]
System.Web.UI.Page.get_Request() +11047544
umbraco.BasePages.BasePage.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
using umbraco; using Nibble.Umb.Datatype.ImprovedMediaPicker;
namespace MyProject.Products { public partial class editProduct : BasePage { public TabPage InfoTab; public TabPage DescriptionTab; public TabPage PropertyTab;
private ImprovedMediaPicker mediaPicker;
private DataHelpers.Product eProduct; private int node;
// The info tab InfoTab = tabControl.NewTabPage(umbraco.ui.GetText("Myproject", "tab_edit_product_info")); //change to xml lang InfoTab.Controls.Add(ProductInfoPane);
//contentPicker = new pagePicker(dataExtractor); //InfoTab.Controls.Add(contentPicker);
var SaveButtonInfo = InfoTab.Menu.NewImageButton(); SaveButtonInfo.ImageUrl = GlobalSettings.Path + "/images/editor/save.gif"; SaveButtonInfo.AltText = umbraco.ui.GetText("buttons", "save"); SaveButtonInfo.Click += new ImageClickEventHandler(Save_Info);
// The description tab DescriptionTab = tabControl.NewTabPage(umbraco.ui.GetText("Myproject", "tab_edit_product_description")); //change to xml lang DescriptionTab.Controls.Add(ProductDescriptionPane);
var SaveButtonDesc = DescriptionTab.Menu.NewImageButton(); SaveButtonDesc.ImageUrl = GlobalSettings.Path + "/images/editor/save.gif"; SaveButtonDesc.AltText = umbraco.ui.GetText("buttons", "save"); SaveButtonDesc.Click += new ImageClickEventHandler(Save_Info);
// The properties tab PropertyTab = tabControl.NewTabPage(umbraco.ui.GetText("general", "properties")); //change to xml lang PropertyTab.Controls.Add(ProductPropPane); }
// save info from product information tab private void Save_Info(object sender, ImageClickEventArgs e) {
if (txtName.Text.Length > 0) { eProduct.name = txtName.Text; }
Looking at your callstack it seems that teh bug is in the onload event of your page. I would set a breakpoint and step through the code to see what line raises the error.
@narthin The improved media picker is a datatype. When you create the datatype you can set some values (prevalues). Normally you use the datatype when you create a document type. When you add an extra property you can choose the type. This is the datatype. On a node the datatype appears as the media picker you want in your custom section. My code loads the datatype and adds it to a placeholder (something similar happens when you render a node which has a property with this datatype). This way all the Umbraco datatypes (like the improved media picker or date picker) can be used in a custom section. I've done it a couple of times and it works :).
In the line below, you set a given ID for the DataType, i guess i can find this in the DB but is there a way to get this by name instead? If I do some other installations on different servers thjis will probably not be the same value?
Ok, so after doing some research iv fouind that Tim's improved mediapicker actually comes as the standard media picker in 4.5 (i just upgraded). So now iv got the following implementation
public partial class editProduct : BasePage { public TabPage InfoTab; public TabPage DescriptionTab; public TabPage PropertyTab;
private DataHelpers.Product eProduct; private int node;
protected override void OnInit(EventArgs e) { imgExtractor = new DataHelpers.ImageDataExtractor(); _mediaChooser = new mediaChooser(imgExtractor, true, true);
//_mediaChooser.Value = "1091"; This dosn't work
pp_image.Controls.Add(_mediaChooser);
// The info tab InfoTab = tabControl.NewTabPage(umbraco.ui.GetText("MyProject", "tab_edit_product_info")); InfoTab.Controls.Add(ProductInfoPane);
//contentPicker = new pagePicker(dataExtractor); //InfoTab.Controls.Add(contentPicker);
var SaveButtonInfo = InfoTab.Menu.NewImageButton(); SaveButtonInfo.ImageUrl = GlobalSettings.Path + "/images/editor/save.gif"; SaveButtonInfo.AltText = umbraco.ui.GetText("buttons", "save"); SaveButtonInfo.Click += new ImageClickEventHandler(Save_Info);
// The description tab DescriptionTab = tabControl.NewTabPage(umbraco.ui.GetText("MyProject", "tab_edit_product_description")); //change to xml lang DescriptionTab.Controls.Add(ProductDescriptionPane);
var SaveButtonDesc = DescriptionTab.Menu.NewImageButton(); SaveButtonDesc.ImageUrl = GlobalSettings.Path + "/images/editor/save.gif"; SaveButtonDesc.AltText = umbraco.ui.GetText("buttons", "save"); SaveButtonDesc.Click += new ImageClickEventHandler(Save_Info);
// The properties tab PropertyTab = tabControl.NewTabPage(umbraco.ui.GetText("general", "properties")); //change to xml lang PropertyTab.Controls.Add(ProductPropPane); }
// save info from product information tab private void Save_Info(object sender, ImageClickEventArgs e) {
if (txtName.Text.Length > 0) { eProduct.name = txtName.Text; }
public class ImageDataExtractor : IData { private object _value;
public ImageDataExtractor() { } public ImageDataExtractor(object o) { Value = o; }
#region IData Members
public void Delete() { throw new NotImplementedException(); }
public void MakeNew(int PropertyId) { throw new NotImplementedException(); }
public int PropertyId { set { throw new NotImplementedException(); } }
public System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d) { throw new NotImplementedException(); }
public object Value { get { return _value; } set { _value = value; } }
#endregion }
I now get a working picker except for one thing. I dont know how to set the initial value? If i have saved a image then i whant it to load the next time i open this page?
Any help with this final problem would be very much appreciated!
That's this problem: http://umbraco.codeplex.com/workitem/29009. I've solved it by changing the source code of Umbraco 4.5 a little bit. Please vote for it so it can be fixed in a next version.
After changing the source code you set the value like this:
_headerImage_DataEditor.PreRender += new EventHandler(HeaderImage_DataEditor_PreRender);
protectedvoidHeaderImage_DataEditor_PreRender(object sender,EventArgs e) { _headerImage_DataEditor.ItemIdValue.Value=HeaderImage.HasValue?HeaderImage.Value.ToString():string.Empty;
Okej, thats a problem then. Do you have a link to the source code for 4.5 (for some reason i cant get source code from codeplex??? unreachble message?)? If I change the BaseTreePicker as you suggested, how would i get it in to a running installation of umbraco 4.5? I cant recompile all files and add them, but if theres only one dll file then there isnt any problem.
Could you give me your e-mail adres so I can send the updated dll to you. You just need to replace the dll in the umbraco bin folder (compiled for 4.5.2) and add the dll as a reference to you visual studio project.
implement improved mediapicker c#
Hi,
Im trying to add the improved mediapicker to my custom section.
I whant to add it by code so that im able to select a image and work with the image id. But i cant get it up and running. I have downloaded the Nibble dll file and added it as a reference in VS. I also uploaded the dll to the umbraco bin folder. Where should i put the other files?(aspx files and webservices).
Is this the correct way to implement the improved mediapicker or am I missing something?
The code compiles but i get and error saying when i run it:
Thanks for anyhelp on this!
Hi,
Looking at your callstack it seems that teh bug is in the onload event of your page. I would set a breakpoint and step through the code to see what line raises the error.
Cheers,
Richard
What you're doing might work, but there is also another solution to this problem. You can load the datatype (with selected prevalues) into your page. You can find more info here: http://our.umbraco.org/forum/developers/extending-umbraco/6863-Datatype-on-normal-page-or-UserControl
Here is sample I've been using:
You might run in this problem: http://umbraco.codeplex.com/workitem/29009
Jeroen
Hi all,
@Richard: Unfortenatly i cant do that since i have to upload my bin file to a server to run on. I dont have a very good test enviroment =(
@Jeroen: Im not sure how this would help me? Could you explain a bit more?
@narthin The improved media picker is a datatype. When you create the datatype you can set some values (prevalues). Normally you use the datatype when you create a document type. When you add an extra property you can choose the type. This is the datatype. On a node the datatype appears as the media picker you want in your custom section. My code loads the datatype and adds it to a placeholder (something similar happens when you render a node which has a property with this datatype). This way all the Umbraco datatypes (like the improved media picker or date picker) can be used in a custom section. I've done it a couple of times and it works :).
Jeroen
Hi again Jeroen,
In the line below, you set a given ID for the DataType, i guess i can find this in the DB but is there a way to get this by name instead? If I do some other installations on different servers thjis will probably not be the same value?
Thx for the help!
Best Regards
Marthin
I don't know if you can do it by name. I always store the id in the web.config app settings so if it would change I could easily update it.
Jeroen
Hi again,
Ok, so after doing some research iv fouind that Tim's improved mediapicker actually comes as the standard media picker in 4.5 (i just upgraded). So now iv got the following implementation
And the Image Extractor
I now get a working picker except for one thing. I dont know how to set the initial value? If i have saved a image then i whant it to load the next time i open this page?
Any help with this final problem would be very much appreciated!
Best of Regards
Marthin
Hi Marthin,
That's this problem: http://umbraco.codeplex.com/workitem/29009. I've solved it by changing the source code of Umbraco 4.5 a little bit. Please vote for it so it can be fixed in a next version.
After changing the source code you set the value like this:
Jeroen
Hi,
Okej, thats a problem then. Do you have a link to the source code for 4.5 (for some reason i cant get source code from codeplex??? unreachble message?)? If I change the BaseTreePicker as you suggested, how would i get it in to a running installation of umbraco 4.5? I cant recompile all files and add them, but if theres only one dll file then there isnt any problem.
thx for all help mr Breuer!
Hi Marthin,
Could you give me your e-mail adres so I can send the updated dll to you. You just need to replace the dll in the umbraco bin folder (compiled for 4.5.2) and add the dll as a reference to you visual studio project.
Jeroen
Hi Jeroen,
That would be great!
you can send it to marthin["at"]student.chalmers.se
where you replace ["at"] with @, dont whant any sniffers to spam my mail =)
Thx for all the help!
Ohh i almost forgott, i use .net 3.5, not the new 4.0
Best Regards
Marthin
Thx to Jeroen this is now solved. Here's my final implementation with the updated controls.dll file.
And the image extractor
Was going to update a old pre 4.5 site with a custom section to 4.7 but ran into this aswell.. The saved value doesnt get set when reloading the page.
Is the umbraco source fix implemented in 4.7?
No the fix is not implemented into Umbraco 4.7: http://umbraco.codeplex.com/workitem/29009. It got declined. Currently I don't use the Umbraco media picker anymore, but I use the Digibiz Advanced Media Picker. This does work on custom page.
Jeroen
Anything written about how to implement DAMP into a custom section?
Sorry not yet. Will probably add it as a wiki to our umbraco.
Jeroen
is working on a reply...