PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

C# VS 2005 : Reading XML file doesn't work

 
 
milkyway
Guest
Posts: n/a
 
      28th Sep 2005
Hi ;-)

I have created a .aspx file that has the following:

DataSet ds = new DataSet();

ds.ReadXml(Server.MapPath("TestInput.xml"));

As far as I can tell, the first line does not work - at all. I just get
"error" in the status field of the browser. How can I check to see what
the problem is for it not executing? I don't know how to check the
return code or use the debugger with this.

Is there something wrong with what I have written altogether?

TIA

 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      29th Sep 2005
Have you considered using an XmlDataSource control ?

http://beta.asp.net/QUICKSTART/util/...TreeView12.src



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaņol : http://asp.net.do/foros/
======================================
"milkyway" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi ;-)
>
> I have created a .aspx file that has the following:
>
> DataSet ds = new DataSet();
>
> ds.ReadXml(Server.MapPath("TestInput.xml"));
>
> As far as I can tell, the first line does not work - at all. I just get
> "error" in the status field of the browser. How can I check to see what
> the problem is for it not executing? I don't know how to check the
> return code or use the debugger with this.
>
> Is there something wrong with what I have written altogether?
>
> TIA
>



 
Reply With Quote
 
milkyway
Guest
Posts: n/a
 
      29th Sep 2005
I was following the examples I had seen on the internet to make the
code work.

I had wanted to get a list of the items on the server and manipulate
the list (on the server).

Is there something I did wrong with what I have used? Is there a pit
that I fell into (perhaps with the creation of the .xml) that would
cause problems? Should I place .xml files in a different directory?

I guess I am kinda lost here as to where I can look for the problem or
how one might use the debugger to track it down ;-(

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      29th Sep 2005
re:
> Is there something I did wrong with what I have used?


The two lines of code you sent are not enough to determine that.

Offhand, did you import the system.data namespace ?

<%@ Import Namespace="System.Data" %>

re:
> Is there a pit that I fell into (perhaps with the creation of the .xml)
> that would cause problems?


It's hard to tell unless you post the xml itself
or run the xml file through an xml validator.

If you want to do the latter, Peter's XML Editor will tell you
if the file's XML is well-formed when you attempt to load it.

Get it at : http://www.iol.ie/~pxe/index.html

re:
> Should I place .xml files in a different directory?


You might as well, since with ASP.NET 2.0 xml data goes in the App_Data dir.

re:
>I was following the examples I had seen on the internet to make the
> code work.


The thing is that data access examples "on the internet", and particularly examples
of binding to xml datasources, are unnecessarily complicated and, if all you want
to do is display the contents of an xml file, just place your xml file in your
application's App_Data directory ( if one doesn't exist, create it ), change
the Datafile's name to your XML's filename, and run this extremely short sample :

ShowXML.aspx:
------------------
<%@ Page Language="VB"%>
<html>
<body>
<form id="showXML" runat="server">
<asp:XmlDataSource id="MySource" DataFile="~/App_Data/your.xml" runat="server"/>
<asp:TreeView
SkinId="Bookstore"
DataSourceId="MySource"
ExpandDepth="3"
MaxDataBindDepth="3"
runat="server"
/>
</form>
</body>
</html>
----------

Easier access to XML data sources is one of
the benefits which ASP.NET 2.0 brings us.




Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaņol : http://asp.net.do/foros/
======================================
"milkyway" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I was following the examples I had seen on the internet to make the
> code work.
>
> I had wanted to get a list of the items on the server and manipulate
> the list (on the server).
>
> Is there something I did wrong with what I have used? Is there a pit
> that I fell into (perhaps with the creation of the .xml) that would
> cause problems? Should I place .xml files in a different directory?
>
> I guess I am kinda lost here as to where I can look for the problem or
> how one might use the debugger to track it down ;-(
>



 
Reply With Quote
 
milkyway
Guest
Posts: n/a
 
      29th Sep 2005
Thanks response Juan - I found the problem ;-P

Basically, the C# code I wrote was to create a .html file for display.
But - what I forgot were the directives so that the C# could run in
peace. When I did:

<%

DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("TestInput.xml"));
%>

Then it worked ;-)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading a local file ASP/VB ,net 2005 AMP Microsoft VB .NET 4 31st Jan 2008 12:19 PM
(newbie) - reading data from a file - in VB 2005 EE Opa Vito Microsoft VB .NET 8 13th Sep 2006 02:37 PM
Publish Web using Remote doesn't work in VS 2005... Rob R. Ainscough Microsoft ASP .NET 2 24th Jan 2006 05:04 PM
C# VS 2005 : Reading XML file doesn't work milkyway Microsoft ASP .NET 4 29th Sep 2005 09:59 PM
Works Suite 2005 Word doesn't work =?Utf-8?B?QmlsbA==?= Microsoft Word Document Management 1 8th Feb 2005 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:35 PM.