I have a custom solution that generates temporary junk files that I need to remove at the end of the process.
I was originally using the following code:
// Loops through the converted PDFs and deletes them from SP.
private void DeleteTempPDFs(List<SPListItem> convertedItems)
{
foreach (SPListItem item in convertedItems)
{
item.Delete();
}
}
I have since discovered that our standard users do not have permission to delete from the library so the code throws an exception when it tries to delete the junk files.
The solutions I can think of is either:
- Temporarily grant the executing user delete permissions
- Pass the code to a service account to execute
Which is the best practise approach in this case? And how would I go about achieving it?
EDIT
I have tried running the code with elevated permissions, this is the exception I am getting: