Problem with reading XML file in ASP

Discussion in 'ASP .Net' started by =?Utf-8?B?VG9tYXMgS2VwaWM=?=, May 17, 2005.

  1. Hi all,

    I want read some data stored in XML document in my aspx page, but I have
    problem with this.

    My XML file settings.xml is:

    <?xml version="1.0" encoding="utf-8" ?>

    <parameters>

    <back_color>blue</back_color>

    <text_color>red</text_color>

    </parameters>

    And here is part of my aspx. page source:

    void ReadIniParameteters()

    {

    XmlTextReader reader = null;

    String args = "ini/settings.xml";

    try

    {

    reader = new XmlTextReader (args); // here it is OK

    while (reader.Read()) // and here occures an error

    {

    switch (reader.NodeType)

    {

    case XmlNodeType.Element:

    Response.Write(reader.Value);

    break;

    }

    }

    }

    catch (Exception e)

    {


    Response.Write("Failed to read the file");

    Response.Write("Exception: " + e.ToString());

    }

    finally

    {

    Response.Write("Processing of the file complete.");

    if (reader != null)

    reader.Close();

    }

    }

    When I run this code an error occures:

    Failed to read the fileException: System.IO.DirectoryNotFoundException:
    Could not find a part of the path "C:\WINDOWS\system32\ini\settings.xml". at
    System.IO.__Error.WinIOError(Int32 errorCode, String str) at
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
    bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode,
    FileAccess access, FileShare share) at
    System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) at
    System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
    ofObjectToReturn)



    What I'm doing wrong? Please help me.

    Tomas


    --
    Tomas
    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, May 17, 2005
    #1
    1. Advertising

  2. as the compiler complaining file is not found: Is there a file like
    "C:\WINDOWS\system32\ini\settings.xml"
    I think answer is no. U should specify file by using
    Server.MapPath("~/ini/Settings.xml") --> this returns full path of the file


    --

    Thanks,
    Yunus Emre ALPÖZEN
    BSc, MCAD.NET

    "Tomas Kepic" <> wrote in message
    news:...
    > Hi all,
    >
    > I want read some data stored in XML document in my aspx page, but I have
    > problem with this.
    >
    > My XML file settings.xml is:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    >
    > <parameters>
    >
    > <back_color>blue</back_color>
    >
    > <text_color>red</text_color>
    >
    > </parameters>
    >
    > And here is part of my aspx. page source:
    >
    > void ReadIniParameteters()
    >
    > {
    >
    > XmlTextReader reader = null;
    >
    > String args = "ini/settings.xml";
    >
    > try
    >
    > {
    >
    > reader = new XmlTextReader (args); // here it is OK
    >
    > while (reader.Read()) // and here occures an error
    >
    > {
    >
    > switch (reader.NodeType)
    >
    > {
    >
    > case XmlNodeType.Element:
    >
    > Response.Write(reader.Value);
    >
    > break;
    >
    > }
    >
    > }
    >
    > }
    >
    > catch (Exception e)
    >
    > {
    >
    >
    > Response.Write("Failed to read the file");
    >
    > Response.Write("Exception: " + e.ToString());
    >
    > }
    >
    > finally
    >
    > {
    >
    > Response.Write("Processing of the file complete.");
    >
    > if (reader != null)
    >
    > reader.Close();
    >
    > }
    >
    > }
    >
    > When I run this code an error occures:
    >
    > Failed to read the fileException: System.IO.DirectoryNotFoundException:
    > Could not find a part of the path "C:\WINDOWS\system32\ini\settings.xml".
    > at
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) at
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
    > Boolean
    > bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode,
    > FileAccess access, FileShare share) at
    > System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
    > at
    > System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
    > ofObjectToReturn)
    >
    >
    >
    > What I'm doing wrong? Please help me.
    >
    > Tomas
    >
    >
    > --
    > Tomas
    Yunus Emre ALPÖZEN [MCAD.NET], May 17, 2005
    #2
    1. Advertising

  3. Hi Yunus, thank you so so so much! This really helps me :).

    I tried use Server.MapPath but I didn't know about sign "~" and so it
    allways returned me the same error. But now it works perfectly!!!

    Thank you so much, on more time.

    Tomas

    --
    Tomas


    "Yunus Emre ALPÖZEN [MCAD.NET]" wrote:

    > as the compiler complaining file is not found: Is there a file like
    > "C:\WINDOWS\system32\ini\settings.xml"
    > I think answer is no. U should specify file by using
    > Server.MapPath("~/ini/Settings.xml") --> this returns full path of the file
    >
    >
    > --
    >
    > Thanks,
    > Yunus Emre ALPÖZEN
    > BSc, MCAD.NET
    >
    > "Tomas Kepic" <> wrote in message
    > news:...
    > > Hi all,
    > >
    > > I want read some data stored in XML document in my aspx page, but I have
    > > problem with this.
    > >
    > > My XML file settings.xml is:
    > >
    > > <?xml version="1.0" encoding="utf-8" ?>
    > >
    > > <parameters>
    > >
    > > <back_color>blue</back_color>
    > >
    > > <text_color>red</text_color>
    > >
    > > </parameters>
    > >
    > > And here is part of my aspx. page source:
    > >
    > > void ReadIniParameteters()
    > >
    > > {
    > >
    > > XmlTextReader reader = null;
    > >
    > > String args = "ini/settings.xml";
    > >
    > > try
    > >
    > > {
    > >
    > > reader = new XmlTextReader (args); // here it is OK
    > >
    > > while (reader.Read()) // and here occures an error
    > >
    > > {
    > >
    > > switch (reader.NodeType)
    > >
    > > {
    > >
    > > case XmlNodeType.Element:
    > >
    > > Response.Write(reader.Value);
    > >
    > > break;
    > >
    > > }
    > >
    > > }
    > >
    > > }
    > >
    > > catch (Exception e)
    > >
    > > {
    > >
    > >
    > > Response.Write("Failed to read the file");
    > >
    > > Response.Write("Exception: " + e.ToString());
    > >
    > > }
    > >
    > > finally
    > >
    > > {
    > >
    > > Response.Write("Processing of the file complete.");
    > >
    > > if (reader != null)
    > >
    > > reader.Close();
    > >
    > > }
    > >
    > > }
    > >
    > > When I run this code an error occures:
    > >
    > > Failed to read the fileException: System.IO.DirectoryNotFoundException:
    > > Could not find a part of the path "C:\WINDOWS\system32\ini\settings.xml".
    > > at
    > > System.IO.__Error.WinIOError(Int32 errorCode, String str) at
    > > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    > > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
    > > Boolean
    > > bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode,
    > > FileAccess access, FileShare share) at
    > > System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
    > > at
    > > System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
    > > ofObjectToReturn)
    > >
    > >
    > >
    > > What I'm doing wrong? Please help me.
    > >
    > > Tomas
    > >
    > >
    > > --
    > > Tomas

    >
    >
    >
    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, May 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wael Soliman

    ASP.NET Reading problem (reading .xls)

    Wael Soliman, Jan 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,779
    =?Utf-8?B?dmluYXk=?=
    Jan 3, 2005
  2. jkflens
    Replies:
    2
    Views:
    1,444
    jkflens
    May 30, 2006
  3. Replies:
    0
    Views:
    771
  4. Erik Wasser
    Replies:
    5
    Views:
    428
    Peter J. Holzer
    Mar 5, 2006
  5. Replies:
    5
    Views:
    68
    Chris Angelico
    May 14, 2014
Loading...

Share This Page