Posts Tagged ‘Programming’

Create a list in all the sites using Powershell

September 20, 2011 3 comments

Here is way to create a list based on a custom template using Powershell. The script will go through each site and create the list and add them to the Quick Launch

$GetSites = Get-SPWebApplication | Get-SPSite | Get-SPWeb -Limit ALL
foreach($getsite in $GetSites)
$listTemplate = $getsite.Site.GetCustomListTemplates($getsite)
$getsite.Lists.Add("MyList","My List",$listTemplate["MyTemplate"])
$list = $getsite.Lists["MyList"]
$list.OnQuickLaunch = $true


Make sure that custom template is uploaded in the List Template Gallery. Check out this link  if you want to add a list template using powershell


How to create Views Programmatically in SharePoint 2010

August 17, 2011 2 comments

Below is the code snippet to create views programmatically

Create a View

      private void CreateView(string strViewName)
string fieldName = //Get Field Internal Name
var docquery = "<Where><Eq><FieldRef Name='" + fieldName.ToString() + "' /><Value Type='Choice'>" + strViewName.ToString() + "</Value></Eq></Where>";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Modified By");
oViewCollection.Add(strViewName, viewFields, docquery, 100, true, false);
catch (Exception e)
throw new SPException(e.Message.ToString());

You can use U2U Query Builder tool to build CAML query (


Web.config Alternatives

February 26, 2011 Leave a comment

Good resource for alternatives of storing configuration data in web.config