Friday, March 8, 2013

Set draft security visibility to document library


To set security that only approver and administrator see pending files
     Set DraftVerrsionVisibility=”2” in Schema.xml

To learn more about DraftVersionvisibility please read this DraftVisibility Types


1-      Using xml
<List xmlns:ows="Microsoft SharePoint" EnableContentTypes="TRUE" Title="Articles" Direction="$Resources:Direction;" Url="Lists/Articles" BaseType="1" xmlns="http://schemas.microsoft.com/sharepoint/" ModeratedList="TRUE" DraftVersionVisibility="2">


2-      Programmatically
   private void applyApproverDraftVisibilityToAllLists(SPWeb oWeb)
        {            oWeb.AllowUnsafeUpdates = true;            SPListCollectionAdapter listAdapter = new SPListCollectionAdapter(oWeb.Lists);            var result = from list in listAdapter                         select list;            foreach (SPList list in result)            {                list.DraftVersionVisibility = DraftVisibilityType.Approver;            }            oWeb.AllowUnsafeUpdates = false;        }public class SPListCollectionAdapter : List<SPList>
    {        private readonly SPListCollection _listCol;        public SPListCollectionAdapter(SPListCollection listCol)        {            _listCol = listCol;            Refresh();        }        private void Refresh()        {            Clear();            foreach (SPList item in _listCol)            {                Add(item);            }        }    }

No comments:

Post a Comment