SharePoint fields are excellent form of reusable asset. There are different types of fields that can be created in the SharePoint environment. As a developer we tend to create some fields as readonly which we could achieve easily while creating the solution using FieldXML in the element.xml file. But there are time when we had to create fields from the SharePoint UI which do not provide the flexibility of setting the field readonly. We would come across these scenarios when we want to have a field that will be used in Workflow or even some times we do not what to show the fields in Edit and Newform of the list or library. It would be an overkill if we create a solution for deploying a readonly field.
There is always poweshell who is our best friend who will never let us down in need. A small script would help achieve this. Below is the script that I wrote to set a list field to readonly.
There is always poweshell who is our best friend who will never let us down in need. A small script would help achieve this. Below is the script that I wrote to set a list field to readonly.
Add-PSSnapin
Microsoft.SharePoint.PowerShell
-ErrorAction
SilentlyContinue
#Get the Web
$web
= Get
-SPWeb
"http://sp2010"
#Get the List
$List
=
$Web
.Lists[
"Daily Email"
]
#Get the Field
$Field
=
$List
.Fields[
"Email User"
]
#Set the field to Read only
$Field
.ReadOnlyField =
$true
$Field
.Update()
No comments:
Post a Comment