Add, Delete and Recycle Bin

  • SPWeb.Folders.Add() will not throw exception if the folder already exists. If that’s the case it will return that folder object. However the parent folder must already exists, versus in C#, Directory.CreateDirectory() will automatically create the whole tree. I had to write my own function to automatically create the whole tree.
  • SPFolder.Delete() and SPFile.Delete() will not throw exception if the folder/file doesn’t exist. So you can just call it directly without checking Exists property. Watch out for checked out file.
  • Items deleted through UI will be in Recycle Bin. (Recycle Bin can be disabled.) But items deleted using delete() API will be deleted permanently (there is a SPFile.Recycle() function that does what it’s named). When a file is restored from Recycle Bin, ItemAdded event will be fired. However no event is fired when a folder is restored.
Advertisements
This entry was posted in Events. Bookmark the permalink.

2 Responses to Add, Delete and Recycle Bin

  1. Kenny says:

    Hi,

    Is it possible to share your code with me that creates a specific folder structure, including subfolders?

    Thanks,

  2. calvin998 says:

    I don’t know what “specific folder structure” you are talking about.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s