2

How do you create application specific config files for a GAC-deployed webpart in SharePoint 2010?

  1. Which one or more of app.config/web.config/supplemental config are appropriate to use for webparts?

  2. Where is the best place for the app.config/web.config file to be placed? According to
    http://msdn.microsoft.com/en-us/library/ms460914.aspx
    it should be placed in
    "\Program Files\Common Files\Microsoft Shared\Web Server Extensions\wpresources",
    but it also mentions

    The web.config files in the \wpresources folders should not be modified. The settings of these files disallow pages or items that can be compiled. If these settings are changed, the security state for the compiled code differs greatly from the security state for code that runs from the Local_Drive:\Inetpub\wwwroot directory.

  3. Can this be done in Visual Studio through including the .config file within the wsp file?

  4. Can this be deployed in one place for a farm, or does it need to be deployed to each server?

From reading the above link, I am thinking that the answers to 1 and 2 are to create a supplemental config in
"\Program Files\Common Files\Microsoft Shared\Web Server Extensions\wpresources" Is this correct?

3 Answers 3

3

Microsoft's patterns & practices group has published guidance for SharePoint 2010, including an heirarchical configuration storage provider as part of "The Application Setting Manager."

Recommended.

1
  • Great article! I don't know why I didn't find this earlier. This exactly addresses the problem.
    – xdhmoore
    Dec 1, 2011 at 20:12
3

I assume you need this because you want to control webpart properties from a central location. Below are the options you can consider :

  1. Use <appsettings> in web.config and read them using ConfigurationManager.AppSettings in webpart.This will allow you to store settings at the scope of web application.

  2. Use a list at Root site or subsites depending on how global you want to store them.The list columns will act as key and the item as values. You will have just one Row in this list. Your webpart will read the list programmatically. One benefit of this approach is You can create versions, in case you want to restore this webpart to previous settings.

  3. For farm level properties, you can use a xml file at */_layouts* folder and consume it in webpart.If you want you can cache it as well.
  4. Hierarchical object store and Property bags.
3
  • 1
    Option 1 is very problematic. SPWebConfigModifications is very obtuse and not generally reliable. Options 2, 3 & 4 are encapsulated in the p&p guidance Dec 1, 2011 at 16:47
  • How does SPWebConfigModifications come into picture here? Dec 1, 2011 at 16:56
  • Thank you for your answer. I think we are going to go with Something like either 2 or 4.
    – xdhmoore
    Dec 1, 2011 at 20:13
1

SharePoint web parts have own settings mechanism base on marking properties with attributes -an example can be found here - http://nishantrana.wordpress.com/2009/01/01/writing-custom-properties-for-web-parts-in-sharepoint/ and http://www.wictorwilen.se/Post/Web-Part-Properties-part-1-introduction.aspx. For more advanced requests you can see EditorPart http://www.wictorwilen.se/Post/Web-Part-Properties-part-2-Editor-Parts.aspx. Also there is a very good book from @Wictor - SharePoint MVP - WebParts in Action - http://www.manning.com/wilen/

Generally, it's not a good way to customize web config, cause it's affects the whole sharepoint web application and require restarting app. But if it's really required - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx to make changes to web.config

If your setting can be viewed by users - you can just create an xml document and deploy it to _layouts folder, when webpart is rendered, it can get data from there.

Also you can deploy configuration xml to feature folder, and get configuration data from there.

2
  • Don't custom properties have to be set on an instance basis? I'm looking for something to change the settings for all instances of a webpart. I know changing the web application web.config file is not the best. I am looking for a way to create an webpart-specific web.config.
    – xdhmoore
    Nov 30, 2011 at 21:12
  • 1
    @xdhmoore - you didn't make this clear in your orig question IMHO.
    – Ryan
    Dec 1, 2011 at 15:55

Your Answer

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

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