Question

I am trying to figure out the internal difference between SPListItem.Delete() and SPFile.Delete().

I wrote a quick PowerShell to delete a document from document library. In my test, I used recycle() instead of delete. Both the methods look as if the result is the same.

So, if I just want to delete a document, is there a difference between calling delete on the list item versus delete on the file object?

Thanks for your help.

Was it helpful?

Solution

Have a look here:

SPFile.Delete

SPListItem.Delete

As I understand SPFile.Delete() method can only delete the file object (from Document Library) while SPListItem.Delete() can be used for List Items as well.

SPListItem.Delete() is also a override function while SPFile.Delete() isn't, but I'm not sure what difference it makes.

OTHER TIPS

Each document/file in Document library have two properties:

All the Metadata properties are represented by SPListItem. And, the actual file is associated with SPFile property.

So when we call SPListItem.Delete() or SPListItem.File.Delete() you are actually deleting the SPListItem, as SPFile can't exists on its own.

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.file.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top