Friday, July 16, 2010

Preventing Folder Creation on MOSS 2007 Document Libraries

Question:

we have created Custom Folder Content types. users are having Contribute permission. They should not allow to create folders, but they can upload documents.

**********************************************************************************
Answers:
------------------------------------
1.Document Library Setting -->Advanced settings --> Folders ( Display "New Folder" command on the New menu? ) click on no radibox.

2. If you attach folder content on the Document library then remove it
Document Library Setting -->Advanced settings -->Content Types -->Remove your content type from Document library.
-----------------------------------
**********************************************************************************
Write event handler:

ItemAdding properties:
if (((string)properties.AfterProperties["ContentType"]) == “Folder”)
{
properties.ErrorMessage = "You can't create folders";
properties.ListItem.Delete();
}
}


Note:

This solution works when the folder is created using the Doc Library menu interface. If, however, the user opens the doc library in Windows Explorer view the ContentType check does not catch it.

Add this and you will catch the Explorer view events as well:

if ((((string)properties.AfterProperties["ContentType"]) == “Folder”) properties.AfterUrl.ToString().Contains(“/”))

No comments:

Post a Comment