Question

I have a custom webpart that was defined with a property like

[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Chart Type"), Category("Chart - Required")]
[InitializationParameterName("ySeriesType")]
public DataSeries1 YSeriesType { get; set; }

which has been deployed. I then changed it to:

[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Chart Type"), Category("Chart - Required")]
[InitializationParameterName("ySeriesType")]
public YSeriesType YSeriesType { get; set; }

This change now causes an error suggesting DataSeries1 was not found. How can I handle the upgrade for this scenario? Fwiw, the following IVersioningPersonalizable did not seem to work:

void IVersioningPersonalizable.Load(IDictionary unknownProperties)
{
    if (unknownProperties == null)
        return;

    _dirty = true;

    foreach (DictionaryEntry entry in unknownProperties)
    {
        switch (Convert.ToString(entry.Key))
        {
            case "YSeriesType":
                this.YSeriesType = (YSeriesType)Enum.Parse(typeof(YSeriesType), Convert.ToString(entry.Value));
                break;
        }
    }
}

protected override void OnInit(EventArgs e)
{
    if (_dirty && null != base.WebPartManager)
    {
        SetPersonalizationDirty();
        _dirty = false;
    }
}

Thanks!

Was it helpful?

Solution

Your IVersioningPersonalizable code looks right, but I think SharePoint determines unknown properties by their name, and if property was not renamed - it will not be unknown...

So, could you please rename YSeriesType property and try to perform the upgrade again?

OTHER TIPS

The error message is referring to the class DataSeries1, which is being used by the existing webpart. So, I'm guessing that you deleted (or renamed) this class.

After executing the code that updates the property values, then you can safely remove your DataSeries1 class.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top