Retrieve image url from cms:CMSEditableImage in code?

Tom F asked on January 3, 2017 01:49

Hi I'm trying to get a url from a CMSEditableImage in the PreRender method of an aspx.cs file so I can use it in a background image.

I have tried

Correct Answer

Juraj Ondrus answered on January 3, 2017 10:46

Hi,
You can use the above macro or, you can take inspiration from the web part itself - \CMS\CMSWebParts\Text\editableimage.ascx.cs and check the code of the LoadContent method:

 public override void LoadContent(string content, bool forceReload)
{
    if (!StopProcessing)
    {
        ucEditableImage.LoadContent(content, forceReload);

        if (!string.IsNullOrEmpty(ucEditableImage.DefaultImage))
        {
            // Default image defined => content is not empty
            EmptyContent = false;
        }
    }
}

Which is also calling the LoadContent method (CMS.Controls.CMSEditableImage.LoadContent(System.String, [System.Boolean])).

2 votesVote for this answer Unmark Correct answer

Recent Answers


Adam Gitin answered on January 3, 2017 08:25 (last edited on December 10, 2019 02:30)

You can try:

CMS.MacroEngine.MacroResolver.Resolve("{% CurrentDocument.DocumentContent.myImage |(identity)GlobalAdministrator%}");

Where "myImage" is the CMSEditableImage webpart ID.

0 votesVote for this answer Mark as a Correct answer

Tom F answered on January 3, 2017 22:29

Thanks Juraj! that inspiration worked perfectly :)

0 votesVote for this answer Mark as a Correct answer

Tim G. answered on June 19, 2018 10:32

@tom-f - is there any chance you could share your solution? Thanks.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.