Allow global configuration of a SharePoint web part
I have creat开发者_Go百科ed a SharePoint web part which has custom properties that the user can configure. However these apply only to that instance of the web part. How could I provide the user a place to allow the user to set properties that would apply to every instance of the web part?
(I'm new to SharePoint development and am using WSPBuilder to create a web part with a feature and deploy it.)
You could use the Property bag of the SPSite's RootWeb (or, to make it SPWeb specific, the current SPWeb) to store global settings for that webpart (in that specific site collection). Create a LAYOUTS page to allowing editing of these settings if it's site collection wide, use RunWithElevatedPrivileges to store properties in an SPWeb's property bag.
Try a static member, eg:
[WebBrowsable(false), Personalizable(PersonalizationScope.Shared)]
public string configSetting
{
get { return _configSetting; }
set { _configSetting = value; }
}
private static string _configSetting;
It has been a bit since I used SharePoint... the first thing I would try is to create a List whose records are the parameters you want to feed to the webpart, and configure it so that the users can only see/modify their own record.
Caveats: this may be tricky if you want to make records dynamically appear whenever a new user registers. And also, lists are "local" to the site, so you can't have a single list which is seen from parts in different sites. (Or at least this is how it worked in SP 2007).
Depending on the number of parameters you need to properly configure the webpart you could also play around with custom "fields" in the user profile, but this is not very robust and would probably be an overkill.
精彩评论