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?
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