SETREADONLY

SETREADWRITE and SETREADONLY are two very special procedures that can be used to allow modfying columns that SharePoint normally does not allow to be modified, such as the Modifed and Create columns in a list. It can for example be useful in backup/restore scenarios. These procedures are not guaranteed to work on all columns. Sealed columns and columns of type COUNTER, cannot as an example, be modified.

SETREADONLY in particular is used to set ReadOnly access on one or more columns.

Note! It is very important to understand that the SETREADWRITE and SETREADONLY procedures both make changes to the list schema and must be used carefully. A SETREADWRITE operation on column that is by default ReadOnly should be followed by a SETREADONLY command in order to restore the column access. It is not recommended to use these procedures excessively and only in controlled environments.

Syntax

SETREADONLY(string listName, string columnNames);

Return value

This method does not return any value.

Example: to set ReadOnly access on the columns Modified and Created in the list Customers:

CALL SETREADONLY('Customers', 'Modified, Created');

Code examples

Update the modified and created columns

using (var command = new SharePointCommand("CALL SETREADWRITE('Customers', 'Modified, Created')", connection))
{
    command.ExecuteNonQuery();
    Console.WriteLine("SETREADWRITE: " + command.LastRecordsAffected);
}

try
{
    using (var command = new SharePointCommand("UPDATE Customers SET Modified = '19801025123000', Created = '19801025123000' WHERE ID = 1", connection))
    {
        command.ExecuteNonQuery();
        Console.WriteLine("Last affected: " + command.LastRecordsAffected);
    }
}
finally
{
    using (var command = new SharePointCommand("CALL SETREADONLY('Customers', 'Modified, Created')", connection))
    {
        command.ExecuteNonQuery();
        Console.WriteLine("SETREADONLY: " + command.LastRecordsAffected);
    }
}

The above example shows how the SETREADWRITE and SETREADONLY can be used to modify columns that are normally ReadOnly.

Code result

SETREADWRITE: 1
Last affected: 1
SETREADONLY: 1


Skip Navigation Links.

Visa     MasterCard