Problem w/ code - updating an existing XML file

Discussion in 'ASP .Net' started by slinky, Jun 13, 2007.

  1. slinky

    slinky Guest

    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>
     
    slinky, Jun 13, 2007
    #1
    1. Advertising

  2. On Jun 13, 7:36 pm, slinky <> wrote:
    > 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.
     
    Alexey Smirnov, Jun 13, 2007
    #2
    1. Advertising

  3. slinky

    slinky Guest

    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
    (?)


    On Jun 13, 5:34 pm, Alexey Smirnov <> wrote:
    > On Jun 13, 7:36 pm, slinky <> wrote:
    >
    > > 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, Jun 14, 2007
    #3
  4. On Jun 14, 4:33 pm, slinky <> wrote:
    > 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
    > (?)
    >
    > On Jun 13, 5:34 pm, Alexey Smirnov <> wrote:
    >
    >
    >
    > > On Jun 13, 7:36 pm, slinky <> wrote:

    >
    > > > 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.- Hide quoted text -

    >
    > - 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>
     
    Alexey Smirnov, Jun 14, 2007
    #4
    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. Wai-Ming Lau

    Re: LoadDataRow not updating existing row

    Wai-Ming Lau, Jul 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    870
    Wai-Ming Lau
    Jul 18, 2003
  2. Billy K.
    Replies:
    0
    Views:
    328
    Billy K.
    Feb 23, 2006
  3. nrm
    Replies:
    3
    Views:
    564
  4. news.rcn.com
    Replies:
    2
    Views:
    1,161
    Roedy Green
    Dec 10, 2007
  5. Martin Honnen
    Replies:
    0
    Views:
    717
    Martin Honnen
    Nov 13, 2009
Loading...

Share This Page