is it possible to limit an image library size
In sharepoint 2007 we have an image libraryy which is using around 2GB of space
we need to limit the library to not allow the user to add more images once it is 2.5 G开发者_开发百科B is that possible in sharePoint and how?
plz help
regards.
Not out of the box. You have to create a class that derives from SPItemEventReceiver and that checks the current size every time an image is added/deleted/updated.
Once the Threshold is reached you can change permissions on the list.
Alternatively, you can do that check in the ItemAdding method and set properties.Cancel = true
in case the threshold is reached.
I don't know off hand what the most efficient approach is since checking file sizes of each list item every time a new one is added is going to be expensive:
long totalSize = 0;
foreach(SPFile file in list.RootFolder.Files){
totalSize += file.Length; // or TotalLength, see MSDN
}
I think I'd just store the current usage in a variable in the SPList.RootFolder.Properties and update it in the ItemAdded/ItemUpdated methods of the Item Event Receiver.
精彩评论