Showing posts with label How to enable Version to document library Programmatically. Show all posts
Showing posts with label How to enable Version to document library Programmatically. Show all posts

Tuesday, December 3, 2013

How to enable Version to document library Programmatically


 public void CheckVersionEnable(string ListName)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite osite = new SPSite("http://URL/"))
                {
                    using (SPWeb oweb = osite.OpenWeb("http://URL/"))
                    {
                        SPList docs = oweb.Lists[ListName];
                        if (docs.EnableVersioning == false)
                        {
                            docs.EnableVersioning = true;
                            docs.MajorVersionLimit = 10;
                            oweb.AllowUnsafeUpdates = true;
                            docs.Update();
                            oweb.AllowUnsafeUpdates = false;
                        }
                    }
                }
            });
        }