Friday, 19 October 2012

enable versioning to sharepoint list


The following is the code snippet which is used to do the versioning settings.
        ///Enable Versioning to lists
        SPContext.Current.Web.AllowUnsafeUpdates = true;
        SPList objList = SPContext.Current.Web.Lists["TestList"];

        //EnableVersioning:- True if versioning is enabled for the document library; Otherwise false.
        objList.EnableVersioning = true;
        //EnableMinorVersions:- true if minor versions are enabled when versioning is enabled for the document library; otherwise false.
        objList.EnableMinorVersions = true;
        //EnableModeration: property is true if Content Approval is enabled; otherwise, false
        objList.EnableModeration = true;
        //ForceCheckout:- This property is true if Forced checkout is enabled for the document library; otherwise false
        objList.ForceCheckout = true;
        //DraftVersionVisibility:- Set the accessibilty of the minor versions of document drafts within the list.
        objList.DraftVersionVisibility = DraftVisibilityType.Author;
        objList.Update();
  SPContext.Current.Web.AllowUnsafeUpdates = false;
       

Sunday, 27 March 2011

Retriving SharePoint WSP Files from Config DB using SharePoint Object Model

WSP files are the preferred way of deploying the new functionlaity in SharePoint. WSP files are stored in the Config DB. If you need to extract these files you can do that by using the SharePoint Object Model Code. The following code snippet will retrive all the solutions from the config DB and will place them in the specified location:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace Retrive_Solutions
{ 
    class SolutionBackup
    {
        static void Main(string[] args)
        {
            SPSolutionCollection AllSolutions = SPFarm.Local.Solutions;
            foreach (SPSolution Solution in AllSolutions)
            {
                SPPersistedFile wspFile = Solution.SolutionFile;
                wspFile.SaveAs("C:\\Solutions\\" + Solution.Name);
            }
        }
    }
}