Problem with reading XML file in ASP

G

Guest

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
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

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
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top