SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a WebPart where I need to set a custom property in SPWeb.AllProperties. How can I on install check to see if a property is set? If it is not set I want to set it. Or is it best just to do this at the top of my normal WebPart code and run it each time?

share|improve this question
up vote 0 down vote accepted

Use the feature activation event of the feature which the webpart is part of. Get the reference of the SPWeb on Feature activation trap and set the property. and reset during the feature de-activation.

But if there is a possibility of the property getting overridden then check it on every load of the webpart and set the value OR display a error message or set


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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