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