Environment: SP2010 Enterprise, VS2012, full server access
Goal: Console application that creates sub-folders in various locations based on user input, and uses SystemUpdate(false) to prevent alerts from triggering.
Where I am thus far: I have a basic console application with prompts for user input and am trying to take that input (things like folder name, library name, etc) and use it to add specific sub-folders anywhere in the library directory structure. I have a code snippet that successfully creates a new top-level folder and then a sub-folder underneath it (using SPListItem the whole way), but I can't figure out how to create a sub-folder in an existing folder/path. The tricky part is that it has to be done with SPListItem, not SPFolder, because SPListItem has the SystemUpdate method that prevents alerts from firing, while SPFolder does not.
Small clarification: The sub-folders are going to go way down the directory structure, not just under a top-level folder.
Here's the code I mentioned:
SPList list = oWeb.Lists[listName]; SPListItem folder = list.AddItem(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, topFolder); folder.SystemUpdate(false); SPListItem SubFolder = list.AddItem(folder.Folder.ServerRelativeUrl , SPFileSystemObjectType.Folder, folderName); SubFolder.SystemUpdate(false);
Ideas? Alternatives? Thanks for your time!
Update: As I was writing this, another problem surfaced. It turns out the SystemUpdate isn't preventing alerts from firing in this case. I have used it in several other programs that change ListItem properties and it worked fine... What's wrong this time?
More thoughts/clarification: I see several people describing almost exactly what I'm doing here and it working. Specifically this post SPListItem.Update() not firing ItemUpdating which uses almost identical code to mine. The difference is I'm using ServerRelativeURL instead of specifying a URL. Does that have any effect on the ItemUpdating event?