6

Environment: SP2010 Enterprise, VS2012, c#, full server access

Simple question...

I'm using a console app to create sub-folders in a document library based on user input, then calling SPListItem.SystemUpdate(false) to keep from triggering alerts. But the alerts are firing anyways, as if it were a regular Update()

Can anyone spot my problem? I'm guessing it has to do with SPItemEventReceiver.ItemAdding method, but I don't know what or how to change that.

Here's the code:

SPList oList = oWeb.Lists[listName];
SPFolderCollection oCol = oList.RootFolder.SubFolders;
SPFolder oFolder = oCol[folderName];
SPListItem newFolder = oList.AddItem(oFolder.Url, SPFileSystemObjectType.Folder, newFolderName);
newFolder.SystemUpdate(false);

Update: Further research on the event receiver involved led me to this page... http://sharepointdevelopertopics.blogspot.com/2011/04/changes-disabling-event-firing-in.html ...which sounds like exactly what I need. BUT it made no difference when I implemented it. The alerts were still triggered. Is that something that simply cannot be done for folder creation? SystemUpdate works fine for changing item properties, but not folders, which is leading me to believe it just can't be done.

Going to keep testing...

Further Updates: Using elevated privileges did not do the trick, nor did updating the SPList as well as the SPListItem. What's really bizzare in my opinion is that even switching the EventFiringEnabled() off and then running the update (as per the link above) doesn't have any effect, alerts still fire normally. I've tried wrapping every piece in SPSecurity/Using SPSite/Using SPWeb, and even specified the list in the event handler class just in case the application had any doubts about my rights or where this was supposed to take place... Still nothing. It seems to be completely ignoring my command to turn off EventFiringEnabled.

Where I am now was: Basically it has come down to the EventFiringEnabled not actually switching off when I tell it to. Is there a good way to troubleshoot this? Or should I just rewrite the whole built-in event handler?

Now where I am: Further update, at some point during all my testing I apparently switched off the event receiver in question, because today NO alerts are firing. I'm revising my code to flip it back on (found the flaw that I think is responsible for leaving it disabled) and going to continue battery testing until I find an answer, but the fact that it actually disabled at SOME point is encouraging. Is there perhaps a timeframe that has to pass or a service that needs to run to make the EventFiringEnabled(false) take effect? Or should it just be immediate? Turns out this was caused by a solution from CodePlex I was testing, "SharePoint Column & View Permission". It (unintentionally) disabled all alerts on the site after I installed it. Uninstalling the wsp set alerts back to normal.

1 Answer 1

5

After relentlessly experimenting until my eyes bled object model code, I have determined that (in this particular situation anyways) you cannot create a folder without triggering an event handler, whether you use SystemUpdate or a custom event receiver.

I also learned that the most commonly referenced ways to use a custom event receiver to prevent alerts from firing when you modify a document's properties, does not work here either. Luckily SystemUpdate still does prevent alerts here.

If anyone can prove me wrong, please please do! But unless that happens, I'm going to call this question closed.

Incidentally I have found an unrelated solution on CodePlex that has a bug which blocks the Immediate Alerts timer job from running after you install it. Uninstalling it sets things back to normal. I want to try to find out how it does this. The solution is here: http://spcolumnpermission.codeplex.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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