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

Forums / Developing with Sitefinity / how can i update a contentlink?

how can i update a contentlink?

2 posts, 0 answered
  1. Rory
    Rory avatar
    44 posts
    Registered:
    22 Mar 2012
    03 May 2012
    Link to this post
    Hello.  i am trying to change an existing contentlink which links an image to a partner object, partner being a CustomModule, similar to product. using SiteFinity 5.

    when we create the partner we choose an image with an image selector and it creates a contentlink between the partner and the image. that works.

    as the partner is about to publish i intercept it at Decorator.ExecuteOnPublish().  here i create a copy of the selected image and put it into a new image library.  that also seems to work (although the filepath doesnt change).

    after the new image is created i try to setup/replace the existing contentlink to point to the new image with the following code:

    ContentLinksManager cman = ContentLinksManager.GetManager();
    Telerik.Sitefinity.Model.ContentLinks.ContentLink cl = cman.GetContentLink(newPartner.Id, typeof(PartnerItem).FullName, "Logo");
    if (cl != null){
          Telerik.Sitefinity.Libraries.Model.Image img = FindImage(cl.ChildItemId);
          if (img != null)
          {
             //create copy of the logo
             Telerik.Sitefinity.Libraries.Model.Image newImage = CopySitefinityImageToLibrary(newAlbum, newPartner.Title + "_Logo", img);

    if (newImage != null)
        if (newImage.Id != Guid.Empty)
             {
         cman.Delete(cl);
         cman.SaveChanges();
     
      Telerik.Sitefinity.Model.ContentLinks.ContentLink newCL cman.CreateContentLink("Logo", newPartner, newImage);
     
      cman.SaveChanges();
     }
      }
      }

    the problem is that the new contentlink doesnt seem to work (but is in the DB).  if i go back into the partner the image does not appear in the selector anymore and when i update the partner and get its contentlink, it is now NULL.

    what else is needed to setup a contentlink properly? i am updating the MASTER partner item which i think is correct.  as usual there is no documentation covering this so any help is appreciated.
  2. Rory
    Rory avatar
    44 posts
    Registered:
    22 Mar 2012
    04 May 2012
    Link to this post
    just fyi, i think what i had above is correct.  

    the problem is with the newly copied image.  the content link changes work if i use an image i uploaded through sitefinity.
2 posts, 0 answered