SigsterSal
New member
- Joined
- Oct 7, 2024
- Messages
- 3
- Programming Experience
- Beginner
Hi
How can I check if Test exist before add
How can I check if Test exist before add
VB.NET:
Function UpdateXmlElement(ByVal element As XElement) As XElement
If element.Name.LocalName.Equals("ContentSources") Then
element.Add(New XElement("ContentSource", "Test"))
Return element
Else
For Each child As XElement In element.Elements()
UpdateXmlElement(child)
Next
End If
Return element
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cuixFile As String = "C:\map\CUI\ORGINAL.cuix"
If Not File.Exists(cuixFile) Then Return
Using zip As ZipArchive = ZipFile.Open(cuixFile, ZipArchiveMode.Update)
'the Header.cui, which is an XML file
Dim entry As ZipArchiveEntry = zip.GetEntry("Header.cui")
If entry.FullName.Equals("Header.cui") Then
'We need to append our custom xaml file to ContentSources element available in Header CUI
Dim fn As String = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
entry.ExtractToFile(fn)
Dim element As XElement = XElement.Load(fn)
' MsgBox(element.ToString)
Dim contentSource As XElement = UpdateXmlElement(element)
contentSource.Save(fn)
entry.Delete()
zip.CreateEntryFromFile(fn, "Header.cui")
File.Delete(fn)
End If
End Using
End Sub
Last edited: