Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've using the following code to save the week a user is currently looking at, for next time they view the web part:

private string _week = null;

[WebPartStorage(Storage.Personal)]
public string Week
{
    get
    {
        if (string.IsNullOrEmpty(_week))
        {
            _week = DateTime.Now.WeekStart(Const.StartOfWeek);
        }

        return _week;
    }

    set
    {
        _week = value;
    }
}

WeekStart is an extension method that returns a string date. Let's assume I'm using a string instead of a date for Good Reasons.

When the following method is called by the 'One week forward' button being clicked, the updated property is saved but only for administrators. For everyone else it fails to save the property:

private void rightArrowClick(object sender, System.EventArgs e)
{
    Week = Week.AddDays(7);

    SaveProperties = true;
}

Am I misunderstanding the purpose of Storage.Personal, or do the normal users need more permissions than the Contributor role allows in order for this to work?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

As far as i remember setting properties requires Designer permissions in SP2010 (due to Fear of XSS). This might explain the behaviour you are seeing.

You may also need to switch:

[Microsoft.SharePoint.WebPartPages.WebPart.WebPartStorage(Storage.Personal)]

for the newer:

[System.Web.UI.WebControls.WebParts.Personalizable(PersonalizationScope.User)]
share|improve this answer
    
Argh. I'd hoped it wouldn't be a permissions problem. Presumably using Elevated Permissions would set the property for the System Account instead of the current user? –  Stuart Pegg Nov 2 '11 at 17:26
    
I guess so. But test first by giving a user Designer permissions to see if this is really the problem –  Anders Rask Nov 2 '11 at 21:39
    
Hmmm... It appears that the setting is being set for all users, rather than being personalised. It also appears to not be permissions based, as it seems only the site creator can change the property... –  Stuart Pegg Nov 3 '11 at 15:06
    
In fact, it's acting exactly like Storage.Shared –  Stuart Pegg Nov 3 '11 at 15:57
    
just saw that you are using the "old" personalization attributes. Are you coding a DWP webpart (SharePoint API) or an ASP.NET web part (recommended)? [Personalizable(PersonalizationScope.User)] More here wictorwilen.se/Post/… –  Anders Rask Nov 3 '11 at 19:02
show 1 more comment

In addition to Anders' answer, I also had to change the SafeAgainstScript attribute in the SafeControl entry for the web part to True, in order for Contributors to be able to change the property.

As an interesting side-effect, those with the Designer role now all share the Shared version of the property. Whereas all normal users have their own personalised versions.

References:

Web part personalization permissions on SharePoint 2010

Personalizable web part custom property not shown for users with Contribute permission level


Word of warning: the SafeAgainstScript attribute is not 2007-friendly, and will fail on installation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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