views:

3464

answers:

6

I have a website in Sharepoint 2007. We use a wsp to deploy our projects. We can deploy dlls, usercontrols, features, but i don't know how to include new lines in the web.config.

Which would be a possible way to make changes in web.config?

Another thing, how can I include resources (resx) in the wsp?

A: 

Regarding web.config files...

Web.config is an XML document that contains configuration settings for a web application. It's located in the root directory of a web application, so for SharePoint, it's usually located in the folder C:\Inetpub\wwwroot\wss\VirtualDirectories\SharePoint80, where SharePoint80 is the name of your web application.

Manually making edits to the web.config file is safe as long as you keep the the tags and sections in the right order. Look at this article.

It's also possible to make changes to it programatically, this post should show you how.

Hope this helps.

dstetsenko
This could be misleading. It is not recommended to modify the web.config in this way for SharePoint. The other answers in this thread provide good advice on how to work with configuration settings within the context of a SharePoint Web Applicaiton.
Tom Resing
+4  A: 

Manually editing the web.config in a multi-server farm is a Bad Idea. Ensuring the web.config files stay in sync on each WFE will become a nightmare quickly.

Using the SPWebConfigModification class to manage web.config changes across the farm is a Good Idea, as changes will be persisted in the SharePoint configuration database, and automatically pushed to every server in the farm.

Having said that, coding against the class can be a pain. Luckily there's a pretty good front-end that's freely available, giving you a configuration screen in Central Administration to add/remove web.config changes.

OedipusPrime
I think it depends on how many WPE you have in your environment.
Tundey
I think it's important to use the out of the box features when it comes to feature deployment. Adding safe controls and custom CAS shuold always be done through the manifest.xml file as it will also save revisions of the web.config file each time. SPWebConfigModification will not.
mortenbpost
I totally agree about using the OOB feature deployment features for managing SafeControls and CAS policies, I just assumed what he wanted to do was outside the scope of that, good call.
OedipusPrime
+2  A: 

there is a very easy way to add safe control entries via Solution. The following snippet added to the manifest.xml will make the relevant modifications to the web.config file. To set other values you should do it in a feature receiver using the SPWebConfigModification class.

<Assemblies>
  <Assembly ...>
     <SafeControl Namespace=".." Assembly="..." Type="..." Safe="True" />
  </Assembly>
  ....
</Assemblies>
Jason
A: 

I think direct web.config manipulation can get tricky when you have multiple servers. If your entire installation is only on a few servers, it just might be easier doing that than trying to make simple web.config changes via code.

Plus, manipulating the web.config directly ensures you have a complete web.config in your source control system. If you use the API to make changes, all you'll have in source control is a bunch of C# code that you hope are bug free!

Tundey
A: 

My advise is not to mess about with any manual modifications through code. Instead, do things the 'SharePoint Way' by placing the modifications in the 12\Config directory as described in Microsoft's SharePoint documentation.

Muhimbi
+1  A: 

In addition, if you think about using appSettings from web.config for your site configuration values, you actually have other options as well. For various reasons web.config might not always be the best place to put your values - at least not if a "superuser", etc. is supposed to be able to change them later on. For this, you could instead use a Config Store-feature, which also scales across the farm for multiple front-end servers, etc.:

http://www.sharepointnutsandbolts.com/2008/05/introducing-sharepoint-config-store-for.html

anchorpoint