Wednesday, September 12, 2012

Hide a column from List Edit Form



I wanted to hide a column from Edit form of a specific list   

function Hide-SPField([string]$url, [string]$List, [string]$Field) {
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 $SPSite = New-Object Microsoft.SharePoint.SPSite($url)
 $OpenWeb = $SPSite.OpenWeb()
 $OpenList = $OpenWeb.Lists[$List]
 $OpenField = $OpenList.Fields[$Field]
 $OpenField.ShowInNewForm = $True
 $OpenField.ShowInEditForm = $False
 $OpenField.ShowInViewForms = $True
 $OpenField.ShowInDisplayForm = $True
 $OpenField.Update()
 $SPSite.Dispose()
 $OpenWeb.Dispose()
 }

 Hide-SPField -url http://yoursite.com/ -List "ListName" -Field "ColumnName"

If you want to hide column in forms across the entire site. you need set the PushChangesToLists property for the changes to be applied to lists where the column has already been added.




#Get the web and site column objects
 $web = Get-SPWeb "http://yoursite.com
 $column = $web.Fields["ColumnName"]
$column.PushChangesToLists = $true
 #Change the ShowInForm property and update objects
 $column.ShowInEditForm = $False
 $column.ShowInNewForm = $False
 $column.ShowInViewForms = $False
 $column.ShowInDisplayForm = $False
 $column.Update()
 $web.Update()
 $web.Dispose()





Move Site Collections between Content Databases



In MOSS 2007 one of content database has grown beyond 100 GB. So I wanted to move couple of existing site collections to another content DB. So I used STSADM to move them.

You can retrieve all the site collections from the source content database using this stsadm command. It will generate a file sites.xml.
stsadm -o enumsites -url http://webAppURL/ –databasename Your_Content_DB > sites.xml

Open sites.xml and remove the sites that you keep in source database. You need to keep site collections entry that you want to move to destination content database. Save the file.
Now run this command to move site collections to another content database.
Merge databases:
stsadm -o mergecontentdbs -url http://webAppURL/ -sourcedatabasename <SourceDB>  -destinationdatabasename <DestinationDB> -operation 3 -filename mysites.xml

In SharePoint 2010 we can achieve the same using PowerShell.
Move-SPSite <URLofSiteColletion> -DestinationDatabase <DestinationDB>