0 out of 1 rated this helpful - Rate this topic

SPField.ReadOnlyField Property

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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
[ClientCallableAttribute]
public bool ReadOnlyField { get; set; }

Property Value

Type: System.Boolean
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.

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 Disposing Objects.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ