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

Forums / Bugs & Issues / Delete Contentlinks?

Delete Contentlinks?

2 posts, 0 answered
  1. Dustin
    Dustin avatar
    20 posts
    Registered:
    05 Jan 2012
    15 Apr 2013
    Link to this post
    We have custom modules that have media items (documents). When a document is deleted from a library, the custom module containing that document still contains the contentlink and is broken. Within Contentlinks, there are ways to get and create links, but not delete? what is the best way to remove a contentlink?????
  2. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    17 Apr 2013
    Link to this post
    Hi Dustin,

    You can call the contentLinksManager and get the content links for the parent item, which will be your dynamic module item. In the query you can search for the name of the field ( the image field in question ) and then get the content links. After that you can remove them safely. Please find the following sample bellow:

    var contentLinksManager = ContentLinksManager.GetManager();
     
          var contentLink = contentLinksManager.GetContentLinks().Where(
                                 c => c.ParentItemId == p.Id
                                 && c.ComponentPropertyName == "myImageField"
                                 ).FirstOrDefault();
     
          if (contentLink != null) contentLinksManager.DeleteItem(contentLink);
          contentLinksManager.SaveChanges();

    Place the source code (the one with the changes on in) in a new web form inside Page_Load and run it. Then make a dummy change in your web.config file, save it, build the project again and run it.

    The following section of our documentation can be useful to you:

    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/ecommerce/products/downloadable-files

    Regards,
    Victor Velev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered