5

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!

2 Answers 2

3

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?

2
  • Yeah it seems like you'd have to leave the name alone; change the display name if it is a problem.
    – Kit Menke
    Commented May 13, 2011 at 13:47
  • Yeah, I knew that I could rename to property a get my IVersionPersonalizable to work, I was hoping I could do a similar function but changing the type without renaming the property. Looks like I am going to have to rename the property to a new name if I am going to change the type.
    – Mr. Young
    Commented May 17, 2011 at 19:42
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.