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

Forums / Developing with Sitefinity / Get Image ContentLink

Get Image ContentLink

3 posts, 0 answered
  1. David
    David avatar
    114 posts
    Registered:
    19 Jul 2012
    05 Jun 2015
    Link to this post

    I'm trying to upload an image to a Library, get a ContentLink for that image and add this to the Dynamic Module I've created.  But I'm not sure how to get the ContentLink during creation of the image?  My code looks like, but GetContentLink expect parameters, but I just want to get the ContentLink for the item I am uploading?

     

    // upload image to the album
    fluent
    .Album(album.Id)
    .CreateImage()
    .Do(item =>
    {
    item.Title = (string)(SiteProperty.GetValue("DisplayAddress") + " "+name);
    imageID = item.Id;
    SiteProperty.SetValue("Images",(ContentLink)item.GetContentLink());
    })
    .CheckOut()
    .UploadContent(stream, ".jpg")
    .CheckIn()
    .Publish()
    .SaveChanges();

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    10 Jun 2015
    Link to this post
    Hello David,

    In order to add image to a DynamicContent Item you can check the code provided in that discussion.

    You can also take a look on that article:
    Add related media custom field to content items

    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
     
  3. David
    David avatar
    114 posts
    Registered:
    19 Jul 2012
    11 Jun 2015 in reply to Svetoslav Manchev
    Link to this post

    Thanks Svetoslav,

    I'd missed a reference:

    using Telerik.Sitefinity.RelatedData;

    And then as per the post creating the link:

    SiteProperty.CreateRelation(item, "Images");

    So upload now looks like:

    // upload image to the album
                        fluent
                        .Album(album.Id)
                        .CreateImage()
                        .Do(item =>
                        {
                            item.Title = (string)(SiteProperty.GetValue("DisplayAddress") + " "+name);
                            imageID = item.Id;
                            SiteProperty.CreateRelation(item, "Images"); //Add ContentLink to dynamic module
                        })
                        .CheckOut()
                        .UploadContent(stream, ".jpg")
                        .CheckIn()
                        .Publish()
                        .SaveChanges();​​

3 posts, 0 answered