Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VB code to update an XML file with root.AppendChild. It was working correctly in the beginning but now it is overwriting an existing node instead of adding a new node. Why would this happen?

VB
Try
    Dim picStr As String
    picStr = Request.QueryString("picInfo")
    Dim strArray(10) As String

    strArray(0) = picStr.Split("/")(0)
    strArray(1) = picStr.Split("/")(1)
    strArray(2) = picStr.Split("/")(2)
    strArray(3) = picStr.Split("/")(3)
    strArray(4) = picStr.Split("/")(4)
    strArray(5) = picStr.Split("/")(5)
    strArray(6) = picStr.Split("/")(6)
    strArray(7) = picStr.Split("/")(7)
    strArray(8) = picStr.Split("/")(8)
    strArray(9) = picStr.Split("/")(9)

    msg = strArray(3)
    Dim newPerson As String = _
        "<image ID='" & strArray(0) & "'>" & Environment.NewLine & " " & _
        "   <filename>" & strArray(0) & "</filename>" & Environment.NewLine & " " & _
        "   <caption>" & strArray(1) & "</caption>" & Environment.NewLine & " " & _
        "</image>"

    Dim xd As New XmlDocument()
    xd.Load(Server.MapPath("../gallery/All/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/AwardsPatrol/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/FundRaising/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/NPS-History/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/NPS-Today/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/Projects/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/SponsorsAndSupporters/gallery.xml"))
    xd.Load(Server.MapPath("../gallery/StudentLife/gallery.xml"))
    Dim docFrag As XmlDocumentFragment = xd.CreateDocumentFragment()
    docFrag.InnerXml = newPerson
    Dim root As XmlNode = xd.DocumentElement
    root.AppendChild(docFrag)

    ' Save the Xml.
    If CInt(strArray(2)) = 1 Then
        xd.Save(Server.MapPath("../gallery/All/gallery.xml"))
    End If
    If CInt(strArray(3)) = 1 Then
        xd.Save(Server.MapPath("../gallery/AwardsPatrol/gallery.xml"))
    End If
    If CInt(strArray(4)) = 1 Then
        xd.Save(Server.MapPath("../gallery/FundRaising/gallery.xml"))
    End If
    If CInt(strArray(5)) = 1 Then
        xd.Save(Server.MapPath("../gallery/NPS-History/gallery.xml"))
    End If
    If CInt(strArray(6)) = 1 Then
        xd.Save(Server.MapPath("../gallery/NPS-Today/gallery.xml"))
    End If
    If CInt(strArray(7)) = 1 Then
        xd.Save(Server.MapPath("../gallery/Projects/gallery.xml"))
    End If
    If CInt(strArray(8)) = 1 Then
        xd.Save(Server.MapPath("../gallery/SponsorsAndSupporters/gallery.xml"))
    End If
    If CInt(strArray(9)) = 1 Then
        xd.Save(Server.MapPath("../gallery/StudentLife/gallery.xml"))
    End If

    Response.Redirect("uploadPics.aspx")
Catch
    Dim TextFile As New StreamWriter(myErrorDir & "errorUploadPicsConfirm_Submit.txt")    'C:\EHC\error\
    TextFile.WriteLine(ex)
    TextFile.Close()
    myExcepValue = ex.ToString()
    If myExcepValue = ("cannot be a zero-length string") Then
        myerror = ("<font color=red size=3>Please fill out all required fields. Thank you.</font>")
        Response.Write(myerror)
    ElseIf myExcepValue.Contains("Thread was being aborted") Then
        'Do nothing. This error is generated by response.redirect by design.
    ElseIf myExcepValue.Contains("No data exists for the row/column") Then
        'Do nothing. This is probably for the spam table.
    Else
        'Call exceptionEmail()
    End If
End Try
Posted
Updated 26-Oct-12 11:43am
v2
Comments
Sergey Alexandrovich Kryukov 26-Oct-12 19:29pm    
What does it mean: "unload"?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900