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

In a Document library I have a content type say "ABC" and I have added an eventhandler to it. I have itemdeleting so that user can not delete file for specific reason. Problem comes when user makes a folder and put files inside that folder. If folder has many files of that content type user can delete entire folder and event handler doesn't work. Event does not fire to stop user. It was working fine in sharepoint 2007. For the solution I tried to make a content type derived from folder and added eventhandler to "myFolder" content type but events are fired only at item adding and item updating not on itemdeleting. I want to stop user from deleting folder. Please Help...

share|improve this question
    
Are you sure that ItemDeleting is not executing? Or do you think it is not firing because the folder gets deleted. It is possible that your code is throwing an exception. If you have not already done so, should should set a breakpoint or add logging to verify whether or not your code is firing. –  Laurie May 17 '11 at 18:03
add comment

2 Answers 2

You can create custom folder content type, and attach the event handler to it.

This can be done through GUI: Site Actions => Site Settings => Galleries => Site content types => Create

Creating custom folder content type

Then, you should go to your list/library settings, enable content type management in Advanced settings, and finally add your newly created content type to the list/library:

Folder content type

After all this done, you can attach an event receiver to your custom folder content type, for example, using SPContentType.EventReceivers.Add() method.

Not tested, but should work.

share|improve this answer
add comment

Create a permission level that does not allow users to delete items. Apply that permission level to the users for that document library. No reason to do this with code. Functionality exists purely OOTB.

share|improve this answer
1  
I believe the reason Anil needs code is that the delete should only be stopped for "a specific reason". –  Laurie May 17 '11 at 18:00
    
If that's the case, then in my opinion, that content type should be isolated to it's own document library and permissioned as such. The data can still be rolled up with other content types based off the Document Content type and you're still using OOTB functionality that already exists. –  PirateEric May 17 '11 at 18:32
add comment

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.