Changes to sharepoint web.config using SPWebConfigModification

I wrote a sharepoint application that needs to change web.config

I have a function that should do all of these configurations. The code for this function is as follows:

SPSite site = properties.Feature.Parent as SPSite; List<SPWebConfigModification> modifications = new List<SPWebConfigModification>(); modifications.AddRange(CustomErrorsModeConfig.Modifications); webConfigModificationHelper.AddWebConfigModifications(site.WebApplication, modifications); 

The CustomErrorsModeConfig.Modifications property contains this code:

 public static SPWebConfigModification[] Modifications = { new SPWebConfigModification() { Owner = WebConfigModificationOwner, Name = "mode", Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute, Path = "system.web/customErrors", Sequence = 0, Value = "Off" } }; 

Then, finally, the webConfigModificationHelper.AddWebConfigModifications method:

 foreach (SPWebConfigModification modification in modifications) { webApp.WebConfigModifications.Add(modification); } webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); webApp.Update(); 

The problem is that I keep getting this error:

 Name cannot begin with the ''' character, hexadecimal value 0x27. Line 1, position 1453 

Could this be a problem with web.config before I try to apply my changes?

Is the SPWebConfigModification property defined incorrectly?

Is there some kind of glitch in my code that leads to this error?

Could there be some property that I am missing (e.g. web.AllowUnsafeUpdates)?

Some sharepoint site configuration?

I tried to solve this problem for some time without any luck :( Any ideas?

+4
source share
3 answers

I can recommend using stsadmwebconfig to make changes to web.config files. I implemented this in many functions, and it has always been a pain, especially during development. Using this tool facilitates its work.

+3
source

I saw this before when the file format is incorrectly set between the file and the declaration.

Open the web.config file in an advanced text editor (Notepad ++ or Visual Studio) and manually set the file type to what is specified. Usually it will be UTF-8.

For more information: http://www.dumpsterdoggy.com/tutorials/?xmlexception-name-cannot-begin-with

+1
source

Try using a list template and take it out of the loop and set the property using simple syntax. Here is a message to set the property in your example, see if you can make it work, and then move on to creating a more general solution with a list and iterating over the elements in the list.

http://www.sharepointkings.com/2008/05/how-to-modify-webconfig-file-in.html

0
source

All Articles