これは、Web パーツのプロパティをファームソリューションに保存する方法です。
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;
正常に動作します。
今、私は同じことを達成する必要がありますが、サンドボックスソリューションでは使用できませSPLimitedWebPartManager
ん。
では、サンドボックス ソリューション Web パーツ内のコードで Web パーツ プロパティを変更するにはどうすればよいでしょうか?