Using ADO 2.8 To Read Intranet Web.config

I was in a process when the need for getting values in the <appSettings> category inside a webservice web.config file which exists on the intranet. If i had the physical file for that webservice, i could impersonate the user and load it inside the XmlDocument and then retrieve the information but due to the fact that the virtual folder is only provided, i had to find a way to get these data. I remembered ADO 2.8 had the stream object which takes the virtual directory as a parameter with 4 other parameters which indeed can solve my problem.

1- We need to Add Reference for Microsoft ActiveX Data Objects 2.8 found in the Com tab.

2- use the below code

   // Create instance of the ADODB stream object
   ADODB.Stream strm = new ADODB.Stream();
   // Set the charset to be ASCII
   strm.Charset = "ASCII";
   // Open the stream - 1 parameter is the Virtual folder for the webservice, 2- Connect Mode, 3- Stream open options, 4 and 5 are the username and password
   strm.Open("url=http://localhost/VBC.SERVICE.V3/web.config",ADODB.ConnectModeEnum.adModeReadWrite, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,"","");
   // New XmlDocument Object
   XmlDocument mydoc = new XmlDocument();
   // Load the web.config data
   mydoc.LoadXml(strm.ReadText(Convert.ToInt32(ADODB.StreamReadEnum.adReadAll)));

Hope it will help someone in the future...

Best Regards,

HC

 

Published 09 May 2007 04:08 PM by haissam

Comments

No Comments

This site

Search

Go

This Blog

Syndication

Sponsors

  • MaximumASP
  • Social Bookmarking
    Online Shopping
    asp.net hosting
    UK online local dating