none
Editing an XML file RRS feed

  • Question

  • I'm new to Linq so... anyway I'm trying on an aspx page in vb.net script to select a particular XML node and display its elements on an edit screen. So far I have an aspx to write new elements and an aspx to diplay all the elements on a grid. I'd like to keep as much of the familiar code below just adding some LINQ to query a node based on a value in a textbox. Any ideas? thanks!!!:

    <script runat="server">
        Private Function MakeDataView() as DataView
            Dim myDataSet As New DataSet()
            myDataSet.ReadXml(Server.MapPath("history.xml"))
            Dim view As DataView = New DataView(myDataSet.Tables(0))
            view.AllowDelete = False
            view.AllowEdit = False
            view.AllowNew = False
            Return view
        End Function

        Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim view as DataView = MakeDataView()
            dgHistory.DataSource = view
            dgHistory.AllowSorting = True
            dgHistory.DataBind()
            Label1.Text = DateAndTime.Now.ToLongTimeString
        End Sub
    </script>
    ___________

        Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
            If Not IsPostBack Then
                Using ds As New DataSet()
                    ds.ReadXml(Server.MapPath("history.xml"))
                    txtNewEvent.DataBind()
                    txtDate.DataBind()
                End Using
            End If
        End Sub

        Private Sub btnSubmit_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnSubmit.Click
            Using ds As New DataSet()
                ds.ReadXml(Server.MapPath("history.xml"))
                Dim dr As DataRow = ds.Tables(0).NewRow()
                dr("entry") = txtNewEvent.Text
                'dr("name") = txtDate.Text
                ds.Tables(0).Rows.Add(dr)
                ds.WriteXml(Server.MapPath("history.xml"))
            End Using
        End Sub


    Monday, December 15, 2008 9:04 PM

All replies

  • This forum is for LINQ to SQL - you will need to move it to the XML forum that covers LINQ to XML at http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/threads/ so the right people see it.

    Thanks,

    [)amien
    Thursday, December 18, 2008 5:20 PM
    Moderator