Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Modify record in xml from code behind on page load and unload events

Posted on 2009-04-06
2
Medium Priority
?
302 Views
Last Modified: 2013-12-17
When my web page opens, I want it to modify a value in an xml file based on what's in its Page.Title, and when the page unloads, modify that value to "Not Broadcasting". I'm having a real hard time figuring this one out--I am going about this all wrong!  Is there an Expert here that can help?
--------###CODE BEHIND###--------
Dim hashTableData As New Hashtable
Dim strWebcastName As String
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            'Reading xml file
            Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument()
            doc.Load(Server.MapPath("~/App_Data/WebcastDemos.xml"))
            Dim list As System.Xml.XmlNodeList = doc.SelectNodes("Records/Record")
            For Each node As System.Xml.XmlNode In list
                hashTableData(node.Item("ID").FirstChild.Value) = node.Item("Data").FirstChild.Value
            Next
            ViewState("Records") = hashTableData
        End If
 
        ' we do this to avoid multiple cast
        Dim myTable As Hashtable = CType(ViewState("Records"), Hashtable)
    End Sub
 
    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        strWebcastName = Page.Title
        Me.ModifyRecord()
    End Sub
 
    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        strWebcastName = "Not Broadcasting"
        Me.ModifyRecord()
    End Sub
 
    Private Sub ModifyRecord()
        Dim key As String = ViewState("HashKey")
 
        CType(ViewState("Records"), Hashtable)(key) = strWebcastName
 
        Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument()
        doc.Load(Server.MapPath("~/App_Data/WebcastDemos.xml"))
 
        Dim myNode As System.Xml.XmlNode = doc.SelectSingleNode("Records/Record[ID='" & key & "']")
        myNode("Data").InnerText = strWebcastName
 
        doc.Save(Server.MapPath("~/App_Data/WebcastDemos.xml"))
    End Sub

Open in new window

0
Comment
Question by:John Account
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Anurag Agarwal earned 2000 total points
ID: 24076543
Where you have set the value of ViewState("HashKey") ??
Anurag

0
 

Author Comment

by:John Account
ID: 24076855
I haven't. And I think the ViewState("HashKey") is completely unnecessary in this scenario, No? I mean, all I want to do is write to and modify a certain field in a certain record of the xml file, when opening the page, and then again when closing the page. So I shouldn't even need a ViewState, right? Just need a way to modify the value directly. Can you help?
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question