I recently had a client requirement where the client wanted to created a “drop box” type of document library, where users were able to modify and view only there own documents. I knew this possible in custom lists through this option being displayed in List Setting / Advanced Settings link.
What I didn’t realise was that this option wasn’t displayed in document libraries. I found this post from Matt Morse that had the solution to this problem. Matt points out that when you take a look in the Microsoft.SharePoint.ApplicationPages.dll the following code exists in the AdvancedSettingsPage class’s OnLoadEvent.
this.ItemLevelSecurityPanel.Visible = (type != 1) && (type != 5);
Where type is the base type of the list (1 = doclib, 5 = issues)
The FixSPSite site = new SPSite(siteUrl);SPWeb web = site.OpenWeb(webUrl);SPList list = web.Lists[listName];PropertyInfo pInfo = list.GetType().GetProperty(propertyName);if (pInfo.PropertyType == typeof(int))pInfo.SetValue(list, Convert.ToInt32(propertyValue), null);elsepInfo.SetValue(list, propertyValue, null);list.Update();web.Dispose();site.Dispose();
The property that we are setting in this case is ReadSecurity and WrtieSecurity the possible values are documented in these MSDN pages. In my case I was setting “Users have read access only to items that they create (2)” and “Users can modify only items that they create (2)”. Using Matt’s tool I basically just entered the following from the command line.
SPSetListProperty “http://server” "/Site" "Document Lib" "ReadSecurity" "2" SPSetListProperty “http://server” "/Site" "Document Lib" "WriteSecurity" "2"
Once this was done the document library performed exactly how we required, now the users who have contribute permissions can use this library to view and edit only their own items, and owners are able to see all items in the document library.