Problem: The SPList object doesn’t contain a property bag. However, a property was assigned indirectly to a list through the RootFolder object through an Elements.xml file in a list instance.
Specifically, the elements XML of a list named List01 could contain the following property named property01 with a value of value01 inside of the Elements element:
<PropertyBag Url="List01" ParentType="Folder" RootWebOnly="FALSE"
xmlns="http://schemas.microsoft.com/sharepoint/">
<Property Name="property01" Value="value01" Type="string" />
</PropertyBag>
You need to assign a different value to value01 using Windows PowerShell.
Solution: From the SharePoint 2010 Management Shell, get the RootFolder of the list and update the property:
# get the web01 web containing list01 in the example contoso web application $web = get-spweb -site "http://www.contoso.com/sites/web01" # get the list, list01 $list = $web.Lists["List01"] # get the RootFolder of the list $root = $list.RootFolder # set the value of property property01 to value02 $root.Properties.property01 = "value02" # save the rootfolder change $root.Update() # dispose of the web $web.Dispose()
Here’s a related problem and solution:
Problem: You need to add a property key and value to a list, but a list doesn't contain a property bag.
Solution: Assign a new key value pair to the rootfolder of the list:
# get the web01 web containing list01 in the example contoso web application $web = get-spweb -site "http://www.contoso.com/sites/web01" # get the list, list01 $list = $web.Lists["List01"] # get the RootFolder of the list $root = $list.RootFolder # create a new key value pair and assign it to the root folder $root.Properties.Add("property04", "value04") # save the change $root.Update() # dispose of the web $web.Dispose()
To see more SharePoint FAQs, go to the SharePoint Pro FAQ page.