Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Failed to edit web.config [modified]

Failed to edit web.config [modified]

Scheduled Pinned Locked Moved C#
questionworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johny Ng
    wrote on last edited by
    #1

    Hello, My question may be very dumb :-( but I couldn't change my web.config using the the following code: XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; doc.Load(@"C:\Web.config"); XmlNode node = doc.SelectSingleNode("/configuration/appSettings"); I don't know why it always returns null. Do you know what I stupidly did wrong? Thanks, Johnny Here is my file

    Mircea PuiuM 1 Reply Last reply
    0
    • J Johny Ng

      Hello, My question may be very dumb :-( but I couldn't change my web.config using the the following code: XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; doc.Load(@"C:\Web.config"); XmlNode node = doc.SelectSingleNode("/configuration/appSettings"); I don't know why it always returns null. Do you know what I stupidly did wrong? Thanks, Johnny Here is my file

      Mircea PuiuM Offline
      Mircea PuiuM Offline
      Mircea Puiu
      wrote on last edited by
      #2

      If the XPath parameter passed to the SelectSingleNode() method does not include a prefix, it is assumed that the namespace URI is the empty namespace. If your XML includes a default namespace (and that is your actual case), you must add a prefix and namespace URI to the XmlNamespaceManager; otherwise, you do not get your node selected ;) So, replace your line: XmlNode node = doc.SelectSingleNode("/configuration/appSettings"); with the following piece of code: XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace"pfx", "http://schemas.microsoft.com/.NetConfiguration/v2.0"); XmlNode node = doc.SelectSingleNode("//pfx:appSettings", nsmgr);

      SkyWalker

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups