Delete Attachment
Last modified by Eduard Moraru on 2026/08/05 17:14
| Programmatically delete an attachment from a document |
| Type | Snippet |
| Category | |
| Developed by | |
| Rating | |
| License | GNU Lesser General Public License 2.1 |
Table of contents
Description
#set ($myDoc = $xwiki.getDocument('Space.Document'))
#set ($attachmentName = 'myattachment.txt') ## delete the attachment with this name
#if ($myDoc.getAttachment($attachmentName))
#set ($moveToRecycleBin = true) ## set this to false if low on space or you just don't want it moved to the recycle bin
$myDoc.document.removeAttachment($myDoc.getAttachment($attachmentName).attachment, $moveToRecycleBin)
$myDoc.save()
#end