Posted By: wacko | Oct 4th, 2005 @ 1:19 PM
page 1 of 1
Comments: 8 | Views: 7977
does anyone know why this would not be working ?


XmlDocument cfgDoc = new XmlDocument();

           
docName = System.Web.HttpContext.Current.Server.MapPath("web.config");

            cfgDoc.Load(docName);

            XmlElement root = cfgDoc.DocumentElement;

            XmlNode node = root.SelectSingleNode("BaseProvider");



the node comes back null, I copied this code into a winforms application and its works fine. I am using the RC bits for VS 2k5.
Sven Groot
Sven Groot
You can't have everything; after all, where would you put it?
It would help to see the xml you're using.
gabe19
gabe19
bang bang shoot shoot
Since you say it works in WinForms, does that mean you are no longer going after the http application context, or did you get context somehow?

I would guess this helps pinpoint the problem; that you are not loading what you think you are loading.
Maurits
Maurits
AKA Matthew van Eerde
Are you calling this from a page in the root directory?  If not you may need to MapPath on "/web.config" rather than "web.config"
wacko wrote:


There's your problem - the configuration element declares a namespace so everything underneath it will be in that namespace.

You'll need to create a namespace manager and use that when you do SelectNode:

XmlDocument cfgDoc = new XmlDocument();
            docName = System.Web.HttpContext.Current.Server.MapPath("web.config");
cfgDoc.Load(docName);

XmlNamespaceManager ns = new XmlNamespaceManager(cfgDoc.NameTable);
ns.AddPrefix("c", "http://schemas.microsoft.com/.NetConfiguration/v2.0");

XmlElement root = cfgDoc.DocumentElement;
XmlNode node = root.SelectSingleNode("c:BaseProvider", ns);
Sven Groot
Sven Groot
You can't have everything; after all, where would you put it?
wacko wrote:
alright I will try that, but why does it work just fine in winforms ? is it just a webapp issue ?

Are you using the exact same xml file in the winforms version? If so, it shouldn't work.
page 1 of 1