Q: How can I change the property bag value that appears at the SharePoint list level?
Q: I need to change a property bag value that appears at the SharePoint list level. I understand that the SharePoint list doesn’t contain a Properties collection. How could this have happened, and how can I change the value for an existing list?
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:
xmlns="http://schemas.microsoft.com/sharepoint/">
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 webapplication$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 webapplication$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.
About the Authors
You May Also Like