[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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?
0
edwbear1976a
Asked:
edwbear1976a
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now