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

Forums / Developing with Sitefinity / Module Builder Media/image fields - Custom Interface widget: Example?

Module Builder Media/image fields - Custom Interface widget: Example?

3 posts, 0 answered
  1. Compton
    Compton avatar
    18 posts
    Registered:
    02 Feb 2012
    06 Nov 2012
    Link to this post
    I have created custom widgets for other Module Builder data types, but I can't seem to figure out how to do so for image fields?     I have seen examples that return the URL of a single image, but the module builder image field seems to requires an array of Guids or some other object.
  2. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    06 Nov 2012
    Link to this post
    I don't have much time to write out a great example, but it will require something along these lines. This code is pretty rough and not optimized best practice. This is just intended to give you some idea what would be needed to get the url string for an image.

    Assuming you have a collection of data from Sitefinity that includes image links...

    foreach (var item in collection)
    {
      // Get a link to an image in a collection
       // Replace "YourImageField" with whatever field stores the images
      var links = (ContentLink[])item.GetValue("YourImageField");
       // Only getting the first image... 
      ContentLink imageLink = links.FirstOrDefault();
     
      // Take the content link above and retrieve the image from the library
      LibrariesManager libManager = LibrariesManager.GetManager();
      var image = libManager.GetImage(img.ChildItemId);
     
      string ImageUrl = image.Url;
    }

    I can provide a better example later if you provide some more specifics regarding your need.
  3. Religare Invesco Asset Management
    Religare Invesco Asset Management avatar
    1 posts
    Registered:
    06 Sep 2013
    15 Mar 2014 in reply to Dan Sorensen
    Link to this post

    Hi Dan Sorensen,

     

    I am following steps given above but I got stuck on line below

    var image = libManager.GetImage(img.ChildItemId);

    in above line you wrote img which is not declared secondly you didn't usedimageLink any where

    ContentLink imageLink = links.FirstOrDefault();

     

    Please tel me how to implement

3 posts, 0 answered