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

Forums / Developing with Sitefinity / Set image of ImageControl with Native API

Set image of ImageControl with Native API

4 posts, 0 answered
  1. Jens
    Jens avatar
    6 posts
    Registered:
    04 Mar 2014
    20 Nov 2014
    Link to this post

     Hello,

     I'm trying to insert an ImageControl into a page, I have it partially done. I get the control on the page
    but I can't set an image. I get the message: "An image was not selected or has been deleted. Please select another one." I tried it with image.Id and image.FileId but both not working. I searched in the
    object for the same GUID as I see in the backend but I can't find that. So, how do I select an image?

    ImageControl imageBlock = new ImageControl();
    imageBlock.ImageId = imageBlock.Manager.GetImages().FirstOrDefault().FileId;
    PageDraftControl imageBlockDraftControl = manager.CreateControl<PageDraftControl>(imageBlock, "Body");
    imageBlockDraftControl.ObjectType = "Telerik.Sitefinity.Web.UI.PublicControls.ImageControl, Telerik.Sitefinity";
    imageBlockDraftControl.Caption = "Image";

  2. Junior Dominguez
    Junior Dominguez avatar
    115 posts
    Registered:
    02 Dec 2016
    25 Nov 2014
    Link to this post
    Hi Jens,

    Notice that the ImageId of the control needs to be the Id of the image in Live version instead of the FileId. For instance:

    imageBlock.ImageId = imageBlock.Manager.GetImages().Where(i=>i.Title=="The image title" && i.Status== Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible==true).Single().Id;


    Best Regards,
    Junior Dominguez
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Jens
    Jens avatar
    6 posts
    Registered:
    04 Mar 2014
    25 Nov 2014 in reply to Junior Dominguez
    Link to this post

    Hi Junior Domingues,

    Thanks for your reaction.
    As I mentioned in my description I tried it with Id and FileId, both didn't work.
    And because the Id field didn't work I started to try other fields like FileId.

     Greetings,
    Jens

  4. Junior Dominguez
    Junior Dominguez avatar
    115 posts
    Registered:
    02 Dec 2016
    27 Nov 2014
    Link to this post
    Hi Jens,

    Running a local test I was able to set the ImageControl using the API and using the image Id and the code snippet provided before as shown in this short video.


    Best Regards,
    Junior Dominguez
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered