473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with reading XML file in ASP

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
Nov 19 '05 #1
2 2043
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" <To********@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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

Nov 19 '05 #2
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" <To********@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
1
by: Magnus Lycka | last post by:
I'm trying to read standard out in a process started with popen2 in a non-blocking way. (Other good ways of doing this than the one I tried are appreciated.) I've tried to dumb down my code to...
7
by: Thomas Sourmail | last post by:
Hi, I hope I am missing something simple, but.. here is my problem: I need my program to check the last column of a file, as in : a b c d target ref 0 0 0 0 1 a 1 0 0 0 1.5 b 2 0 0 0 2 c
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: Fabrice | last post by:
Hello, (Alain) Tis is a part of my code to retrieve text from hastable in memory cache, by reading (befor) a resources file. Thanks for your help. /1/ The resources file * I have create a...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.