Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
SPField Class
SPField Properties
 ReadOnlyField Property

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPField.ReadOnlyField Property (Microsoft.SharePoint)
Gets or sets a Boolean value that specifies whether values in the field can be modified.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Property ReadOnlyField As Boolean
Visual Basic (Usage)
Dim instance As SPField
Dim value As Boolean

value = instance.ReadOnlyField

instance.ReadOnlyField = value
C#
public bool ReadOnlyField { get; set; }

Property Value

true to specify that the field cannot be modified; otherwise, false.

The following code example makes a field read-only in a specified list on a root Web site.

Visual Basic
Using oSiteCollection As New SPSite("http://MyServer")
    Using oWebsite As SPWeb = oSiteCollection.OpenWeb()
        Dim oList As SPList = oWebsite.Lists("MyList")
        Dim oItem As SPListItem = oList.Items(0)
        oItem.Fields("MyField").ReadOnlyField = True
        oItem.Fields("MyField").Update()
    End Using
End Using
C#
using (SPSite oSiteCollection = new SPSite("http://MyServer"))
{
    using (SPWeb oWebsite = oSiteCollection.OpenWeb())
    {
        SPList oList = oWebsite.Lists["MyList"];
        SPListItem oItem = oList.Items[0];
        oItem.Fields["MyField"].ReadOnlyField = true;
        oItem.Fields["MyField"].Update();
    }
}
NoteNote:

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker