4

Yes, the nodes are being alphabetically sorted and the Sequence property only applies when the Name property is exactly the same. To fix, use a little XPath trickery to get your nodes to sort in the correct order (first modules[1=1] then modules[2=2]): SPSecurity.RunWithElevatedPrivileges(delegate { SPWebService spWebService = SPWebService....


3

Unless it's a formatting issue with the question then the mod.Value = String.Format("", ...) is giving an empty string. You want something like: mod.Value = String.Format("<add name="{0}" connectionString="{1}" ProviderName="{2}" />", ...)


2

i would suggest to store your configuration key/values NOT in web.config but in a property bags (e.g. http://msdn.microsoft.com/en-us/library/ff798340.aspx), because the handling is much more easy. but this would cause a redesign of your application.


2

I found the problem: my solution was in Sandboxed mode! Changed the "Sandboxed solution" project's property to False and now it compiles :)


2

You need to add the web part type as safe control in the web applications "web.config" file and in the configuration > SharePoint > SafeControls section. The general format is like below: Just replace AssemblyName, AssemblyVersion, AssemblyCulture, AssemblyPublicKeyToken, The class name of the web-part and The class name of the web-part with the information ...


1

You cannot restore the Configuration database. What you can do is create a farm-only backup using Backup-SPFarm -ConfigurationOnly. This will backup the Web Configuration/Web Service configuration. You should always be using the SPWebConfigurationModification class to store web.config changes; there shouldn't be a need to backup the web.config files ...


1

It is highly advisable that donot run the query against the SharePoint DB. Yes, you need to take the backup of the Web.Config files from all Web front end for all web applications. Script will touch each web.config of each web application on every server.


1

Actually it is in the Objects table. Try SELECT [Id] ,[ClassId] ,[ParentId] ,[Name] ,[Status] ,[Version] ,[Properties] FROM [SharePoint_Config].[dbo].[Objects] WHERE properties like '%SPWebConfigModification%' As others have mentioned, it is not advisable to query the DB directly.


1

For others that find this thread due to searching for the "Object reference not set" error when trying to call SPWebConfigModifications.Remove... In my case this was caused by the SPWebConfigModification being created with a null value for the 'name' property. I had to programmatically set the name (make sure it is unique). Then I could remove the item.


1

There is an example on Technet illustrating how to remove WebConfigurationSection's in PowerShell here. This will delete all entries, but you could easily change it to work for specific sections: #=================================================================== # function to remove all existing node and changes to attributes matching the Owner name #==...


1

Okay I found a solution with a console app - seems like a previous modification was stuck: SPWebApplication webapp = site.WebApplication; webapp.WebConfigModifications.Clear(); webapp.Update(); webapp.WebService.WebConfigModifications.Clear(); webapp.WebService.ApplyWebConfigModifications(); ...


1

Check the permission on the inetpub folders or the folder of that web app and compare with the permission in test environment.


1

It appears that this is because you are calling ApplyWebConfigModifications() on the wrong SPWebService object. From How To: Modify the web.config file in SharePoint using SPWebConfigModification: Use the ApplyWebConfigModifications() method on the SPWebApplication object you are saving your SPWebConfigModification object to. I don’t understand why this ...


1

I just got a notification from Stack Overflow that I got a badge for this question based on views, and I didn't even remember asking this question on SPOverflow, because it didn't really exist at the time. The point is, I also asked this question on SO and got a correct answer there: "Just like ContentService, SPWebService has an AdministrationService ...


Only top voted, non community-wiki answers of a minimum length are eligible