How to get Image field from page attributes - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

How to get Image field from page attributes

  • How to get Image field from page attributes
  • Hello,

    I create  a RelatedMediaField to custum my "Edit Page" : (Administration->Advanced->ContentView->Controls->FrontEndPages->FrontEndPagesCreate)

    Problem : How can I get this image url ?

    node.GetValue<Telerik.Sitefinity.Libraries.Model.Image>("MyMediaField").Url;

    => Error : System.Exception: Wrong custom field 'MyMediaField' for type 'Telerik.Sitefinity.Pages.Model.PageNode'

    Maybe DataFieldName attribute bad done ?

    Please help.

    Thanks !!

     

  • Help please ?

    Thanks !!

  • Hello,

    There are two ways to get related items with Sitefinity API, using related data API and using ContentLinksManager.

    Related data API
    using Telerik.Sitefinity.RelatedData;
     
    var pageManager = PageManager.GetManager();
                 var page = pageManager.GetPageNodes().Where(t => t.Title == "Test").FirstOrDefault();
               
                 var relatedImage = page.GetRelatedItems<Telerik.Sitefinity.Libraries.Model.Image>("Image");

    ContentLinksManager
    var pageManager = PageManager.GetManager();
                
              
       
                var page = pageManager.GetPageNodes().Where(t => t.Title == "Test").FirstOrDefault();
     
                var contentLinksManager = ContentLinksManager.GetManager();
                var linksToRelatedItems = contentLinksManager.GetContentLinks()
                                                                               .Where(cl => cl.ParentItemId == page.Id &&
                                                                                  cl.ParentItemType == page.GetType().FullName &&
                                                                                                  cl.ComponentPropertyName == "Image");
                //in the property ChildItemAdditionalInfo the url of the image resides
               var relatedItemUrl = linksToRelatedItems.Select(s => s.ChildItemAdditionalInfo);


    Regards,
    Stanislav Velikov
    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
     
  • d6c6521e-37c1-6deb-a958-ff0000446526_sans-titre.png

    Thanks for reply.

    Please see in file enclosed the result. I dont see any URL ...

    You think it's working ?

     

    Thanks.

  • Hello Medy,

    Both methods works fine (screenshot of the test).

    You can try to recreate the related media field - Images, using the UI:
    - Pages menu > Custom Fields link on the right side

    Regards,
    Svetoslav Manchev
    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