Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Okay got it. The sub-folder in which you want to create the new folder can be selected by getting a folder collection and then indexing it, like this:

SPFolderCollection oCol = oList.RootFolder.SubFolders;
SPFolder oFolder = oCol[oSubFolder];

...then adding it with the url like so:

SPListItem newFolder = oList.AddItem(oFolder.Url, SPFileSystemObjectType.Folder, newFolderName);

So now I'm just down to figuring out why SPListItem.SystemUpdate(false) is not working. It seems to just do a regular SPListItem.Update() instead. Will post this in a new question.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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