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.


Have a look here:



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.

| improve this answer | |
  • Thanks Gintas. But I am still unable to get a definite answer on the difference and how the end-result may be different. In my test, there was no difference in the outcome. That's the part I am trying to figure out. – Dixit Mirza Nov 3 '16 at 16:35
  • 1
    I think they're the same when it comes to Document Library, as SPFile deletes a document (file), SPListItem deletes the document item (properties), both of them cannot exist without each other in a Library, so I assume you can delete any of them. Personally, I would stick to SPFile object while working with Libraries :) – Gintas K Nov 3 '16 at 16:42
  • @Dixit Mirza For your purposes it does matter which approach to use, but I guess if you are iterating through SPListItemCollection than using SPListItem.Recylce/Delete is slightly less convoluted than SPListItem.File.Delete. Both of these methods to exactly the same thing. The reason we have two methods: SPListItem does not always have File property value. SPFile does not always have SPListItem property value. this is why we have the same thing implemented twice. It's just so happens that documents libraries have both SPListItem and SPFile referencing each other – Denis Molodtsov Nov 3 '16 at 19:15
  • Thanks Denis. Do you mean to say that for my purposes it does NOT matter which approach I use? Thanks for the insight. – Dixit Mirza Nov 3 '16 at 19:37
  • I am not sure which answer to mark as answer? – Dixit Mirza Nov 30 '16 at 17:34

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.


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.