Welcome to Atalasoft Community Sign in | Join | Help

Using SPWebConfigModification, Part 5 - The Remedy

 

The Remedy

 

Ok, so now the Name property is only an XPath expression if it’s a child node.  Then what do we do with sections that have attributes?  They must be child nodes, and so created as EnsureChildNode type.  I’ll modify the code a little bit so that the first if statement looks like this:

if (string.IsNullOrEmpty(name) && node.HasChildNodes) {…

And move the Name property update into the Else{} block.  Try that!  Nope.  When SharePoint tries to process the  node under the <location path="_some/path/here"> node it freaks out saying it can’t find it!  Ok, now what?  Well, if we consider everything a section up until you get to a node that has attributes, then switch to EnsureChildNode types from there on, will that work?

Again, we change the first if statement and remember the parent’s type:

SPWebConfigModification.SPWebConfigModificationType parentType = mod.Type;

mod = new SPWebConfigModification(node.Name, GetOuterPath(node.ParentNode));

if (string.IsNullOrEmpty(name)

    && parentType == SPWebConfigModification.SPWebConfigModificationType.EnsureSection

     && node.HasChildNodes) { …

 

Now we’re off and running.  Everything in our fragment web.config file will be an EnsureSection type until that node has no child nodes, it has attributes, or its parent type wasn’t EnsureSection (it’s a child of a child).  In this way, you can build a web.config file fragment and not worry that you’ll add a modification child node when that node’s full path doesn’t yet exist!

I'll show you how to put this to work in Part 6!

 

Published Wednesday, October 08, 2008 1:20 PM by dterrell

Comments

Wednesday, October 08, 2008 1:23 PM by If you build it, They will come

# Using SPWebConfigModification, Part 6

We're in Part 3 of a 6 part blog post about the SPWebConfigModification object and my trials with it.

Thursday, October 16, 2008 11:57 AM by DotNetKicks.com

# Using SPWebConfigModification, Part 5 - The Remedy

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Anonymous comments are disabled