using relative or absolute url or maybe sever.mapppath when I'm developing or publishing to load an xml file

HI Guys:

I'm developing a web  proyect and the connection string is in a label in a xml page.. I kow how to handle it but when I use the method Load(Url) I have a doubt.. that's why I run the web app proyect from my  VEstudio IDe virtual server that is not the same when I have to publish for internet purposes.

this is the code that I use for development pursposes
/*

 try
           {
               XmlDocument oTagDocumento = new XmlDocument();
               oTagDocumento.Load(_UrlFile);

               XmlNodeList oTagConexiones = oTagDocumento.GetElementsByTagName("CONECCIONES");
               XmlNodeList oTagListaConexion = ((XmlElement)oTagConexiones[0]).GetElementsByTagName("CONECCION");

               

               foreach (XmlElement nodo in oTagListaConexion)
               {
                   int i = 0;
                   XmlNodeList olstLlave = nodo.GetElementsByTagName("LLAVE");

                   XmlNodeList olstValor = nodo.GetElementsByTagName("VALOR");

                   if (olstLlave[i].InnerText == _NombreEtiquetaLlave)
                   {
                       sResultado = sResultado + olstLlave[i].InnerText.ToString() + olstValor[i].InnerText.ToString();
                       break;
                   }
               }

           }

           catch (System.IO.FileNotFoundException e)
           {
               sResultado = e.Message;
           }
           catch (Exception e)
           {
               sResultado = sResultado + e.Message;
           }

*/

Where the url is absolute path, but what about when I publish it, I want to use the same relative/absolute path on developping time or when I publish it. Maybe I have to use the Server.MappPath method but HOw?
edwbear1976aAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sasapopovicCommented:
Hi,

I would suggest next:

1. Edit web.config file
2. Locate <appSettings> section.
3. If there is no <appSettings> section then add one (it should be under the <configuration> section)
4. Add a new parameter to <appSettings> section that defines the full URL to your XML page. The section may look like this:

  <appSettings>
    <add key="XmlPageFullURL" value="http://myserver/myapp/xmlpage.aspx"/>
   </appSettings>
5. Change next line:
oTagDocumento.Load(_UrlFile);
into:

oTagDocumento.Load(ConfigurationManager.AppSettings["XmlPageFullURL"]));

(or you can leave that line as it was before and set _UrlFile variable to value returned by ConfigurationManager.AppSettings["XmlPageFullURL"]).

In your development environment set the XmlPageFullURL parameter's value to full URL (or relative URL if that works also) to xml page on your machine and in other environments (like test, acceptance, production) set different URLs.

Regards,
Sasa
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
edwbear1976aAuthor Commented:
Hi SaSa and thanx for your comments
well  Ithe UrlFile that I load is about the db connection string.. looking at this code I think that this might be usefull, Let me try it tomorrow, I feel this is going to work.
0
edwbear1976aAuthor Commented:
Hi Sara. I've been trying to use the ConfigurationManager class but I couldn't find it. what super class does it belong? do I have to importe or use some class spaces?

0
sasapopovicCommented:
ConfigurationManager is a class from System.Configuration namespace (and System.Configuration.dll).
It is a new class in .NET 2.0 so if you are working on a .NET 1.1 project then you should use old classes to read from application configuration file.
0
edwbear1976aAuthor Commented:
Okey, Saaa, I just found it . I added the reference System.Configurarion to my proyect and then I impotted it and it worked GREAT!!!!!
Thanx so much!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.