Set image of ImageControl with Native API
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"
;
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;
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
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