This is the way I save a property of my webpart in a farm solution:
SPContext.Current.Web.AllowUnsafeUpdates = true;
SPFile file = SPContext.Current.File;
SPLimitedWebPartManager mgr = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
for (int index = 0; index < mgr.WebParts.Count; index++)
{
if (mgr.WebParts[index].ID == this.ID)
{
((MyWebpartType) mgr.WebParts[index]).MyStringProperty = "Hello World!";
mgr.SaveChanges(mgr.WebParts[index]);
}
}
SPContext.Current.Web.AllowUnsafeUpdates = false;
Works fine.
Now I have to achieve the same but in a sandbox solution but there is no SPLimitedWebPartManager
available.
So how can I change a webpart property by code inside a sandbox solution webpart?