0

I have the following code below. The first time I run this code it doesnt create the property in the propertybag. The second time it will create the property. Why???

string newValue = new JavaScriptSerializer().Serialize(members);
            string currentValue = web.AllProperties[propertyName] as string;

            if (!newValue.Equals(currentValue))
            {
                web.AllProperties[propertyName] = newValue;
                needsUpdate = true;
            }

            if (!web.IndexedPropertyKeys.Contains(propertyName))
            {
                web.IndexedPropertyKeys.Add(propertyName);
                needsUpdate = true;
            }

            if (needsUpdate)
            {
                web.Update();
            }

UPDATE:

if (!web.IndexedPropertyKeys.Contains(propertyName))
            {
                web.IndexedPropertyKeys.Add(propertyName);
                needsUpdate = true;
            }

if (!newValue.Equals(currentValue))
            {
                web.AllProperties[propertyName] = newValue;
                needsUpdate = true;
            }

            if (needsUpdate)
            {
                web.Update();
            }
0

Please add the property before you update it. It is creating the property in the first run and updating the value in the second run.

  • see my update. Like this? – Ola Sep 10 '15 at 13:50
  • Yes, is it working? – Vamsi K K Sep 10 '15 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.