Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to update web.config in SharePoint when the feature is activated. I have created Event receiver. The code inside receiver is:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = (properties.Feature.Parent as SPSite).WebApplication;

        SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");
        modification.Owner = "modifyAccountFeatureOwner";
        modification.Sequence = 0;
        modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
        modification.Value = "Off";         
        webApp.WebConfigModifications.Add(modification);

        webApp.Update();            
        webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); 
    }

When I'm deploying feature I have received the following error: "Error occurred in deployment step 'Activate Features': Expression must evaluate to a node-set."

What is wrong with this?

share|improve this question
    
Welcome to SharePoint Stack Exchange! Please tag by feature or topic and not by version or product. This helps to attract more attention to your question and keep it relevant. See How do I use tags for general guidelines. –  Alex Angas Sep 14 '11 at 5:48

2 Answers 2

up vote 0 down vote accepted

I think the error occurs on this line:

SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");

And the problem is the second parameter

"system.web/customErrors"

which is an XPath expression. And this expression seems to be incorrect, which means it does not select an existing node in the web.config file. It probably has to be:

"configuration/system.web/customErrors/@mode"

Please note: I did not test this.

share|improve this answer

Add the following line after webApp.WebConfigModifications.Add(modification);

webApp.WebConfigModifications.Clear();

it clears all the non-required modifications from the object.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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