2

I have a solution where I am including a webconfig.Name.xml modification file in the CONFIG mapped folder. The problem is, it is only applied if I add a post-build step of:

stsadm -o copyappbincontent

Which is not desirable. I was wondering if there is any other way, other than SPWebConfigModification?

Any best practices for this kind of work?

0

1 Answer 1

0

I think you can use the SPWebConfigModification without stsadm requirement. here is the example:

Lets say you want to change mode value to Off.

<configuration>
    <system.web>
       <customErrors mode="On">
    <system.web>
 <configuration>

here is the code

private void SimpleSample()
 {
     // Get an instance of my local web application
     SPWebApplication webApp = new SPSite("http://localhost").WebApplication;
 
     // Create my new modification to set the mode attibute to "Off".
     // Example: <customErrors mode="Off">
     SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");
     modification.Owner = "SimpleSampleUniqueOwnerValue";
     modification.Sequence = 0;
     modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
     modification.Value = "Off";
     // Add my new web.config modification.
     webApp.WebConfigModifications.Add(modification);    
// Save web.config changes. 
     webApp.Update();
     // Applies the list of web.config modifications to all Web applications in this Web service across the farm.
     webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications
 }

read more over here: How To: Modify the web.config file in SharePoint using SPWebConfigModification

Managing Web.config Modifications

3

Your Answer

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

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