Delete Contentlinks?

Posted by Community Admin on 04-Aug-2018 18:54

Delete Contentlinks?

All Replies

Posted by Community Admin on 15-Apr-2013 00:00

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

Posted by Community Admin on 17-Apr-2013 00:00

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:

www.sitefinity.com/.../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

This thread is closed