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

Forums / Developing with Sitefinity / How to get Image field from page attributes

How to get Image field from page attributes

5 posts, 0 answered
  1. Medy
    Medy avatar
    15 posts
    Registered:
    05 Oct 2015
    25 Nov 2015
    Link to this post

    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 !!

     

  2. Medy
    Medy avatar
    15 posts
    Registered:
    05 Oct 2015
    26 Nov 2015
    Link to this post

    Help please ?

    Thanks !!

  3. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    30 Nov 2016
    30 Nov 2015
    Link to this post
    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
     
  4. Medy
    Medy avatar
    15 posts
    Registered:
    05 Oct 2015
    30 Nov 2015 in reply to Stanislav Velikov
    Link to this post

    Thanks for reply.

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

    You think it's working ?

     

    Thanks.

  5. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    09 Dec 2015
    Link to this post
    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
     
5 posts, 0 answered