Hi Guys,
Thanks for visiting Blog .
In one of my previous posts We have created Site Column in SharePoint Site using Out of box feature.
In current post ,we are going to create a Site Column using Power Shell Script and Server object Model as well.
First , I will show the Power Shell Script to create a site Column .
$site = Get-SPSite -Identity "Site URL" // Add the Site URL here $web = $site.RootWeb $fieldXML = '' $web.Fields.AddFieldAsXml($fieldXML) $web.Dispose() $site.Dispose()Note : Save the Script in notepad and save the text file with .ps1 extension in drive . Copy the Script location with extension. Open-->Power Shell(Run As Administrator) Now you can check the site Column created under Group "EmployeeInformation". Second , I will show how to create a site Column using C# (Programatically)..
private static void CreateSiteColumn() { try { string SiteColumnName = "IndiaMyCountry"; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite("Server URL")) { SPWeb web = site.RootWeb; //Create Site Column //Add choice Field "India" if (!web.Fields.ContainsField(SiteColumnName)) { string countryField = web.Fields.Add(SiteColumnName, SPFieldType.Choice, true); //Set the Field Properties SPFieldChoice CityInIndia =(SPFieldChoice)web.Fields.GetField(SiteColumnName); //Set the group for the Site column CityInIndia.Group = "States"; //Add the choices string[] States = new string[] { "TamilNadu", "Kerala", "Andhr Pradesh","karnataka"}; CityInIndia.Choices.AddRange(States); //Set the default value CityInIndia.DefaultValue = "TamilNadu"; //Set Fillable value CityInIndia.FillInChoice = true; //Update the field CityInIndia.Update(); } } }); } catch (Exception ex) { //Exception Handling } }
Related Post
SharePoint 2010
- List view render using JSLink with Fabric UI
- Delete Quick Links using Powershell
- delete/Add Top Navigation Links using Powershell
- PowerShell::Get Content Database Size in SharePoint
- PowerShell :: Delete All List Items
- Basics: Difference between Synchronous Events and Asynchronous Events in SharePoint
- Remove-SPSite 0x80070003 - Forcely delete Site Collection that cannot be deleted
- This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.
- Restore-SPSite: The operation that you are attempting to perform cannot be completed successfully.
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint Interview Questions and Answers..
- What are Event Receivers and How to Create Sample event Receivers and attach to List/ Doc Library ?
- Export SharePoint Search Crawl log to CSV File.
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- SharePoint Modal Dailoge to Open Page
- SPDataSource in SharePoint.
- Capacity planning and Sizing in SharePoint 2010
- Enable 'Save site as Template' in Publishing Sites by using SharePoint Designer
- Read Enhanced Rich Text Values in SharePoint
- What is Web part life Cycle in SharePoint 2013 and SharePoint 2010
- How to Hide Controls in SharePoint New Form Based on User using ECMA Script.
- What is the Content Type for Custom List in SharePoint 2013, SharePoint 2010
- What is calculated column in SharePoint 2013 ,2010
- Create Meetings by using Exchange Server API
Powershell
- Delete Quick Links using Powershell
- delete/Add Top Navigation Links using Powershell
- Get CheckedOut Files from SharePoint 2013 and MOSS2007
- PowerShell::Get Content Database Size in SharePoint
- PowerShell :: Delete All List Items
- Powershell :: Apply Master Page to all sub sites under site collection
- Get Site Collections specific to a Content Database and Export to CSV
- Remove-SPSite 0x80070003 - Forcely delete Site Collection that cannot be deleted
- Check Whether PowerShell Process is 32-bit or 64-bit?
- How to send Email by using Powershell in SharePoint
- Admin SVC must be running in order to create deployment timer job
- WSP Deployments in SharePoint using Powershell
- Create Site Collection by using Power Shell
- Create Web Application by using Powershell
- Backup Site Collection/Sub site/List(Library) in Share Point
- Get Site Collection Details using STSADM
- WSP Backup from Central Administration in Share Point
- Deactivate/Delete Site Template through Power shell
0 comments:
Post a Comment