I've created a Campaign Monitor plugin for 2.40, and in the Uninstall method of the installation service I would like to delete any settings that the plugin has saved, however I can't find a way of doing this. The Setting Service has a DeleteSetting method that requires a Setting object as the only parameter. Unfortunately I can't seem to create a Setting object even if I know the key for the setting. The setting service has a method GetSettingById which requires me to know the Id (which I dont) and then there is a method GetSettingByKey<> but this doesnt return a setting object, it returns a type.
Does anyone know how to get hold of a setting when you know the key?
I've created a Campaign Monitor plugin for 2.40, and in the Uninstall method of the installation service I would like to delete any settings that the plugin has saved, however I can't find a way of doing this. The Setting Service has a DeleteSetting method that requires a Setting object as the only parameter. Unfortunately I can't seem to create a Setting object even if I know the key for the setting. The setting service has a method GetSettingById which requires me to know the Id (which I dont) and then there is a method GetSettingByKey<> but this doesnt return a setting object, it returns a type.
Does anyone know how to get hold of a setting when you know the key?
Thanks Al
You probably store your settings in a class that inherits ISettings, as in
DeleteSetting with generic param is not in 2.40. You'll need to just DeleteSetting() each of your settings individually.
Hi - and how would you do that? DeleteSetting takes a Setting as its parameter, but all I know is the key of the setting. How basically do you create a setting object from the key???
Thanks for your response. Strangely, that doesnt work for me in 2.40 - I get the error message The object cannot be deleted because it was not found in the ObjectStateManager.
My code is as so:
foreach (var setting in _settingService.GetAllSettings()) { if (setting.Key.StartsWith("widgets.googleanalytics.googleid.") || setting.Key.StartsWith("widgets.googleanalytics.javascript.")) { _settingService.DeleteSetting(setting.Value); } }
It's most odd that it doesnt work. Any thoughts?
Regards, Al
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hai ancora qualche domanda o hai bisogno di aiuto?