Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Problem w/ code - updating an existing XML file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
slinky - 13 Jun 2007 18:36 GMT
I have an aspx for with a textbox and a button. The goal is to simply
have the user type a message, hit the button and it should append to
the XML file. I can open the aspx in the browser with no problem, but
the XML file does not get updated. What's wrong with this code?
Thanks!

<script runat="server">
   Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
       If Not IsPostBack Then
           Dim ds As New DataSet()
           ds.ReadXml(Server.MapPath("timeline.xml"))
           txtNewEvent.DataBind()
           ds.Dispose()
       End If
   End Sub

   Private Sub btnSubmit_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnSubmit.Click
       Dim ds As New DataSet()
       Try
           ds.ReadXml(Server.MapPath("timeline.xml"))
           ds.Tables(0).Rows(0).Item("Event") = txtNewEvent.Text
           ds.WriteXml(Server.MapPath("timeline.xml"))
       Catch
       Finally
           ds.Dispose()
       End Try
   End Sub
</script>
Alexey Smirnov - 13 Jun 2007 22:34 GMT
> I have an aspx for with a textbox and a button. The goal is to simply
> have the user type a message, hit the button and it should append to
> the XML file. I can open the aspx in the browser with no problem, but
> the XML file does not get updated. What's wrong with this code?
> Thanks!

Try to remove Try...Catch...Finally...End Try block

It should give you an error.
slinky - 14 Jun 2007 15:33 GMT
I commented out this:

       'Try
       'ds.ReadXml(Server.MapPath("timeline.xml"))
       'ds.Tables(0).Rows(0).Item("Event") = txtNewEvent.Text
       ' ds.WriteXml(Server.MapPath("timeline.xml"))
       ' Catch
       ' Finally
       'ds.Dispose()
       ' End Try

But I see no errors in the error list and I can still display the page
in the browser, both controls, no errors, but no updating of course to
the XML file... so the basic logic in my code must have a major flaw
(?)

> > I have an aspx for with a textbox and a button. The goal is to simply
> > have the user type a message, hit the button and it should append to
[quoted text clipped - 5 lines]
>
> It should give you an error.
Alexey Smirnov - 14 Jun 2007 21:52 GMT
> I commented out this:
>
[quoted text clipped - 23 lines]
>
> - Show quoted text -

<%@ Import Namespace="System.Data" %>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
       If Not IsPostBack Then
           Dim ds As New DataSet()
           ds.ReadXml(Server.MapPath("timeline.xml"))
           'txtNewEvent.DataBind()
           ds.Dispose()
       End If
   End Sub

   Private Sub btnSubmit_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnSubmit.Click
       Dim ds As New DataSet()
       'Try
       ds.ReadXml(Server.MapPath("timeline.xml"))
       ds.Tables(0).Rows(0).Item("Event") = "it works"
       ds.WriteXml(Server.MapPath("timeline.xml"))
       'Catch
       'Finally
       ds.Dispose()
       'End Try
   End Sub

</script>
<form id=form1 runat=server>
<asp:button id="btnSubmit" runat="server" text="Button" />
</form>

<?xml version="1.0" standalone="yes"?>
<xml>
 <DataObjects>
   <Event>it works</Event>
 </DataObjects>
</xml>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.