Small "trap" in property bags Object Model"

Source: Internet
Author: User

Debugging A SharePointProgramA bug was found. In SharePoint 2007, spweb, spfolder, and splistitem all provide a convenient property bags feature to store custom property information, just like this:

Splistitem item = ...;
Item. properties ["myprop1"] = "propvalue1 ";
Item. properties ["myprop2"] = "propvalue2 ";
Item. Update ();

The bug I found is that some custom attributes stored in spweb. properties are not correctly saved to the content database. Check carefully and find out the cause. This small problem is indeed easy to becomeCodeSo Let's remind you.

Spfolder, splistitem property bags (that is, spfolder. properties/splistitem. properties) are implemented directly using a hashtable. When we call spfolder. update () or splistitem. when updating (), you can write the data in their property bags back to the content database.

However, spweb. properties is a custom sppropertybag class (inherited from system. collections. specialized. implemented by calling spweb. update () does not write the data in property bags back to the content database, but calls sppropertybag. update () method. Example:

Spweb web = spcontext. Current. Web;
Web. properties ["myprop1"] = "propvalue1 ";
Web. properties. Update ();

I don't know why they have such design differences, but I guess the biggest possibility is that the implementation of spfolder/splistitem and spweb is not written by a developer, the developer who wrote spfolder/splistitem thought it was enough to use a simple hashtable. The developer who wrote spweb thought it was necessary to define a sppropertybag class, in this way, the sppropertybag can be reused for different classes in the project that require the property bags feature. Unfortunately, as the old saying goes: "developers carefully designed the stuff for reuse, 90% of the possibilities will not be reused "...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.