Mass delete operations
Using the Services API, you can perform mass delete operations on Documents and their associated files, as well as on other object types. The account used to perform these operations must be a system admin with Delete Object Dependencies permissions.
The methods, classes, and the enumeration used to perform mass delete operations are available in the kCura.Relativity.Client namespace.
Note: For the code samples provided on this page, you can assume that the APIOptions object on the proxy has the appropriate token and WorkspaceID.
This page contains the following information:
- MassDeleteOptions and DocumentMassDeleteOptions classes
- MassDeleteAllDocuments() method
- MassDeleteDocuments() method
- MassDelete() method
- MassDeleteAllObjects() method
MassDeleteOptions and DocumentMassDeleteOptions classes
When calling the mass delete methods, you need to pass an instance of the MassDeleteOptions or DocumentMassDeleteOptions class. These classes provides information about how to delete objects.
DocumentMassDeleteOptions class
You pass an instance of the DocumentMassDeleteOptions class to the MassDeleteDocuments() or MassDeleteAllDocuments() methods. To indicate how to perform the deletion, you can set either or both of the following fields on the DocumentMassDeleteOptions class to true or false:
- Force Delete – removes the selected Documents even if they have redactions, annotations, links, or tags.
- Cascade Delete – removes the selected Documents, as well as deletes all child objects and unlinks associative objects.
In addition, you can use the DeleteType enumeration to specify the type of files associated with the Documents that you want to delete:
- AllAssociatedFiles – indicates that you want to delete Documents and all dependent files, including images and native files. It also results in the deletion of field values.
- Images – indicates that you want to delete only the images associated with the selected Documents.
- Natives – indicates that you want to delete only the native files associated with the selected Documents.
- ImagesAndNatives – indicates that you want to delete only the images and native files associated with the selected Documents. (The field values for the documents aren't deleted.)
MassDeleteOptions class
You pass an instance of the MassDeleteOptions class to the MassDelete() or MassDeleteAllObjects methods. It indicates the type of the object that you want to delete, as well as whether you want to delete all dependent objects by performing a cascade delete. You can set the Cascade Delete field to true when you want to delete all child objects and unlink associative objects.
MassDeleteAllDocuments() method
You can use the MassDeleteAllDocuments() to delete all Documents and their associated files in the Workspace. This code sample illustrates how to set the CascadeDelete and ForceDelete fields on the DocumentMassDeleteOptions object when deleting all Documents and their associated files in a Workspace.
public static bool Using_MassDelete_ToCascadeAndForceDeleteAllDocumentsInWorkspace(IRSAPIClient proxy)
{
//STEP 1: Set up delete options.
var deleteOptions = new DocumentMassDeleteOptions(DocumentMassDeleteOptions.DeleteType.AllAssociatedFiles);
deleteOptions.CascadeDelete = true;
deleteOptions.ForceDelete = true;
//STEP 2: Delete all documents.
var result = proxy.MassDeleteAllDocuments(proxy.APIOptions, deleteOptions);
//STEP 3: Check for success.
if (!result.Success)
{
Console.WriteLine(result.Message);
return false;
}
return true;
}
MassDeleteDocuments() method
You can use the MassDeleteDocuments() method to delete all files , images, natives, or both the images and natives associated with a Document. You must use a DeleteType enum to specify the file types that you want to delete, and then list the ArtifactID of each Document.
This code sample illustrates how to force delete images for the Documents with the specified ArtifactIDs. A force deletion removes even Documents containing redactions and annotations from the Workspace.
public static bool Using_MassDelete_ToForceDeleteImagesForSpecificDocuments(IRSAPIClient proxy)
{
//STEP 1: Set up delete options.
var deleteOptions = new DocumentMassDeleteOptions(DocumentMassDeleteOptions.DeleteType.Images);
deleteOptions.ForceDelete = true;
//STEP 2: Call the mass delete method on the ArtifactIDs you want to delete.
var result =
proxy.MassDeleteDocuments(proxy.APIOptions, deleteOptions, new List<int> {1033456, 1033457, 1033458});
//STEP 3: Check for success.
if (!result.Success)
{
Console.WriteLine(result.Message);
return false;
}
return true;
}
MassDelete() method
The MassDelete() method removes a list of objects from the Workspace. You must specify the ArtifactType of the objects, and then list the ArtifactID of each object to delete. This code sample illustrates how to perform a cascade delete on the objects of the specified type.
public static bool Using_MassDelete_ToCascadeDeleteSpecificObjectsOfSpecificType(IRSAPIClient proxy)
{
//STEP 1: Set up delete options.
var deleteOptions = new MassDeleteOptions(1033451);
deleteOptions.CascadeDelete = true;
//STEP 2: Call mass delete on the ArtifactIDs you want to delete.
var result =
proxy.MassDelete(proxy.APIOptions, deleteOptions, new List<int> {1033456, 1033457, 1033458});
//STEP 3: Check for success.
if (!result.Success)
{
Console.WriteLine(result.Message);
return false;
}
return true;
}
MassDeleteAllObjects() method
The MassDeleteAllObjects() method removes all objects of the specified ArtifactType from the Workspace. This code sample illustrates how to delete all objects of the specified type without using cascade delete, which means that dependent objects aren't deleted.
public static bool Using_MassDelete_DeleteAllObjectsOfSpecificTypeInWorkspace(IRSAPIClient proxy)
{
//STEP 1: Set up delete options.
var deleteOptions = new MassDeleteOptions(1033451);
deleteOptions.CascadeDelete = false;
//STEP 2: Call mass delete on the object type.
var result = proxy.MassDeleteAllObjects(proxy.APIOptions, deleteOptions);
//STEP 3: Check for success.
if (!result.Success)
{
Console.WriteLine(result.Message);
return false;
}
return true;
}