CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Opening XML File via Relative Path

    Hi guys,

    I'm sure this is a total noob question to you, but I'm finding it quite hard to locate an answer to this!

    I want to be able to read strings from an XML file so I can use them in my code.

    The thing is, I want to do this from within a class, which means I can't use the xmlDataSource control (like <asp:xmlDataSource.....)

    All of the examples I find either use the xmlDataSource control (which seems like it needs to be put on a page) or a relative path (like @"C:\myxmlfile.xml")

    I can't use a relative path because that will prevent the app from being moved around (without having to modify variables)

    have been trying it like this:
    Code:
    XmlReader r = XmlReader.Create("~/App_Data/LwICTProxy_Services.xml");
    If anyone can help me it would be greatly appreciated

  2. #2
    Join Date
    Dec 2008
    Location
    Pakistan
    Posts
    7

    Re: Opening XML File via Relative Path

    Well, if you have a web application then you can use,
    XmlReader r = XmlReader.Create(Server.MapPath(".") + "/App_Data/LwICTProxy_Services.xml");

    or desktop application use,

    XmlReader r = XmlReader.Create(Application.StartupPath + "/App_Data/LwICTProxy_Services.xml");

  3. #3
    Join Date
    Jul 2009
    Posts
    2

    Re: Opening XML File via Relative Path

    Awsome, thanks very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured