Copied to clipboard

Flag this post as spam?

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


  • marthin 87 posts 106 karma points
    Oct 13, 2010 @ 11:57
    marthin
    0

    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:

    [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;

    protected void Page_Load(object sender, EventArgs e)
    {
    this.node = int.Parse(Request["id"]);

    pp_name.Text = umbraco.ui.GetText("general", "name");
    pp_price.Text = umbraco.ui.GetText("MyProject", "price");
    pp_image.Text = umbraco.ui.GetText("defaultdialogs", "insertimage");

    // load the product
    eProduct = DataHelpers.ProductLoader.loadProduct(node);

    if (!IsPostBack){

    if (eProduct != null)
    {
    txtName.Text = eProduct.name;
    txtPrice.Text = eProduct.price.ToString();
    txtFullDescription.Text = eProduct.text;
    txtShortDescription.Text = eProduct.short_text;

    }
    }

    }

    protected override void OnInit(EventArgs e)
    {

    mediaPicker = new ImprovedMediaPicker();

    pp_image.Controls.Add(mediaPicker);

    // 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;
    }

    eProduct.price = decimal.Parse(txtPrice.Text);
    eProduct.text = txtFullDescription.Text;
    eProduct.short_text = txtShortDescription.Text;



    DataHelpers.ProductUpdater.updateProduct(eProduct);


    }
    }
    }

     

    Thanks for anyhelp on this!

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Oct 13, 2010 @ 12:17
    Richard Soeteman
    0

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 13, 2010 @ 12:44
    Jeroen Breuer
    1

    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:

    private mediaChooser _headerImage_DataEditor;
    
    protected override void OnInit(EventArgs e)
    {
        //Add the header image to the details tab.
        DataTypeDefinition headerImageDatatype = DataTypeDefinition.GetDataTypeDefinition(1035);
        _headerImage_DataEditor = (mediaChooser)headerImageDatatype.DataType.DataEditor;
        _headerImage_DataEditor.PreRender += new EventHandler(HeaderImage_DataEditor_PreRender);
        PlaceHolderHeaderImage.Controls.Add(_headerImage_DataEditor);
    }
    
    protected void HeaderImage_DataEditor_PreRender(object sender, EventArgs e)
    {
        _headerImage_DataEditor.ItemIdValue.Value = HeaderImage.HasValue ? HeaderImage.Value.ToString() : string.Empty;
    
        base.OnPreRender(e);
    }
    
    protected void SaveButton_Click(object sender, ImageClickEventArgs e)
    {
        int headerId = Convert.ToInt32(_headerImage_DataEditor.ItemIdValue.Value);
    }

     

     

    You might run in this problem: http://umbraco.codeplex.com/workitem/29009

    Jeroen

  • marthin 87 posts 106 karma points
    Oct 13, 2010 @ 14:34
    marthin
    0

    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?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 13, 2010 @ 14:42
    Jeroen Breuer
    0

    @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

  • marthin 87 posts 106 karma points
    Oct 14, 2010 @ 14:36
    marthin
    0

    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?

    DataTypeDefinition headerImageDatatype = DataTypeDefinition.GetDataTypeDefinition(1035);

    Thx for the help!

     

    Best Regards

    Marthin

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 14, 2010 @ 14:56
    Jeroen Breuer
    0

    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

  • marthin 87 posts 106 karma points
    Oct 15, 2010 @ 10:41
    marthin
    0

    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

    public partial class editProduct : BasePage
    {
    public TabPage InfoTab;
    public TabPage DescriptionTab;
    public TabPage PropertyTab;


    private DataHelpers.Product eProduct;
    private int node;

    private mediaChooser _mediaChooser;
    private DataHelpers.ImageDataExtractor imgExtractor;

    protected void Page_Load(object sender, EventArgs e)
    {
    this.node = int.Parse(Request["id"]);

    pp_name.Text = umbraco.ui.GetText("general", "name");
    pp_price.Text = umbraco.ui.GetText("MyProject", "price");
    pp_image.Text = umbraco.ui.GetText("defaultdialogs", "insertimage");


    // load the product
    eProduct = DataHelpers.ProductLoader.loadProduct(node);

    if (!IsPostBack){

    if (eProduct != null)
    {
    txtName.Text = eProduct.name;
    txtPrice.Text = eProduct.price.ToString();
    txtFullDescription.Text = eProduct.text;
    txtShortDescription.Text = eProduct.short_text;
    }
    }

    }

    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;
    }

    eProduct.price = decimal.Parse(txtPrice.Text);
    eProduct.text = txtFullDescription.Text;
    eProduct.short_text = txtShortDescription.Text;



    DataHelpers.ProductUpdater.updateProduct(eProduct);
    //if (Page is BasePage)
    //{
    ((BasePage)Page).speechBubble(BasePage.speechBubbleIcon.save, ui.GetText("eCommerce", "speechbubble_update_product"), ui.GetText("eCommerce", "speechbubble_update_product_small"));

    //}


    }
    }
    }

     

    And the Image Extractor

     

     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!

    Best of Regards

    Marthin

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 15, 2010 @ 11:04
    Jeroen Breuer
    1

    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:

    _headerImage_DataEditor.PreRender += new EventHandler(HeaderImage_DataEditor_PreRender);
    
    protected void HeaderImage_DataEditor_PreRender(object sender, EventArgs e)
    {
            _headerImage_DataEditor
    .ItemIdValue.Value = HeaderImage.HasValue ? HeaderImage.Value.ToString() : string.Empty;

           
    base.OnPreRender(e); }

    Jeroen

  • marthin 87 posts 106 karma points
    Oct 15, 2010 @ 11:10
    marthin
    0

    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!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 19, 2010 @ 09:39
    Jeroen Breuer
    0

    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

  • marthin 87 posts 106 karma points
    Oct 19, 2010 @ 10:16
    marthin
    0

    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

  • marthin 87 posts 106 karma points
    Oct 19, 2010 @ 13:42
    marthin
    0

    Thx to Jeroen this is now solved. Here's my final implementation with the updated controls.dll file.

    public partial class editProduct : BasePage
    {
    public TabPage InfoTab;
    public TabPage DescriptionTab;
    public TabPage PropertyTab;


    private DataHelpers.Product eProduct;
    private int node;

    private mediaChooser _mediaChooser;
    private DataHelpers.ImageDataExtractor imgExtractor;

    protected void Page_Load(object sender, EventArgs e)
    {
    this.node = int.Parse(Request["id"]);


    pp_image.Text = umbraco.ui.GetText("defaultdialogs", "insertimage");



    // load the product
    eProduct = DataHelpers.ProductLoader.loadProduct(node);


    if (!IsPostBack){

    if (eProduct != null)
    {
    txtName.Text = eProduct.name;
    txtPrice.Text = eProduct.price.ToString();
    txtFullDescription.Text = eProduct.text;
    txtShortDescription.Text = eProduct.short_text;
    }
    else
    {
    Response.Write("Could not load product.");
    }
    }

    }

    protected void mediaChooser_PreRender(object sender, EventArgs e)
    {
    _mediaChooser.ItemIdValue.Value = "1091";
    base.OnPreRender(e);


    }

    protected override void OnInit(EventArgs e)
    {
    imgExtractor = new DataHelpers.ImageDataExtractor();
    _mediaChooser = new mediaChooser(imgExtractor, true, true);
    _mediaChooser.PreRender += new EventHandler(mediaChooser_PreRender);

    pp_image.Controls.Add(_mediaChooser);

    // The info tab
    InfoTab = tabControl.NewTabPage(umbraco.ui.GetText("MyProject", "tab_edit_product_general"));
    InfoTab.Controls.Add(GeneralInfo);
    InfoTab.Controls.Add(GeneralDescription);
    }

    // save info from product information tab
    private void Save_Info(object sender, ImageClickEventArgs e)
    {

    }
    }

    And the image extractor

    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
       
    }

     

  • Johan Möller 83 posts 137 karma points
    May 31, 2011 @ 13:23
    Johan Möller
    0

    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?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 31, 2011 @ 13:33
    Jeroen Breuer
    0

    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

  • Johan Möller 83 posts 137 karma points
    Jun 27, 2011 @ 16:19
    Johan Möller
    0

    Anything written about how to implement DAMP into a custom section?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 27, 2011 @ 16:21
    Jeroen Breuer
    0

    Sorry not yet. Will probably add it as a wiki to our umbraco.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft