Cancelling and deleting attachments
You can cancel added attachment objects of features using the CancelAttachmentEdits method of the AttachmentManager class. To cancel edits for individual attachment objects, use the CancelAttachmentEditsUsingAttachmentIds method.
You can delete single attachment objects from the existing attachments that are associated with a feature. When a deleted attachment is uploaded, it is also deleted from the back-end database.
This topic discusses how to cancel attachment edits and delete attachments.
Cancelling edits to attachments
- Cancel attachment edits using an array of feature IDs.
//cancel the attachments of features 615 and 902 int[] fids = { 615, 902 }; bool isCancel = manager.CancelAttachmentEdits(fids);
- Cancel added attachment edits using an array of attachment IDs.
//get the attachments added to features 615 and 902 QueryFilter qf = new QueryFilter("OBJECTID = 615 OR OBJECTID = 902"); EditState editState = EditState.Added; IList<Attachment> attachments = manager.GetAttachments(qf, editState); //populate the attachment Ids list int [] attachmentIds = new int[attachments.Count]; for (int i=0; i<attachments.Count; i++) attachmentIds[i] = attachments[i].Id; //cancel the attachments of features 615 and 902 bool isCancel = manager.CancelAttachmentEditsUsingAttachmentIds(attachmentIds);
Deleting attachment information
In the next section, you will delete some attachment objects, so that when they are uploaded, they are removed from the back-end database.
- Attachment deletion is done on a per attachment basis. To do this, pass an attachment ID for deletion.
//Retrieve the list of original attachments belonging to feature 902, QueryFilter qf = new QueryFilter("OBJECTID = 902"); EditState editState = EditState.Original; IList<Attachment> attachments = manager.GetAttachments(qf, editState); //get the Id of the first attachment, then mark it as deleted int attachmentId = attachments[0].Id; bool isDeleted = manager.DeleteAttachment(attachmentId)
1/7/2015