I want to create a XML file. I have this code, but nothing is written into the file ... it only creates a blank xml file.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim openFolder As New FolderBrowserDialog Dim saveFile As New SaveFileDialog Dim sw As IO.StreamWriter Dim path As String Dim file As String Dim data As String Dim images() As String Try Button1.Enabled = False openFolder.ShowDialog() saveFile.FileName = "*.xml" saveFile.Filter = "XML File|*.xml" saveFile.ShowDialog() If openFolder.SelectedPath <> "" Then path = openFolder.SelectedPath If saveFile.FileName <> "" Then file = saveFile.FileName images = IO.Directory.GetFiles(path) data = "<images directory=""photos/Nuit de la Joke"">" + vbNewLine For i As Integer = 0 To images.Length - 1 If IO.Path.GetExtension(images(i)) = ".jpg" Then data += "<imageNode jpegURL=""" & IO.Path.GetFileName(images(i)) & """ thumbURL=""" & IO.Path.GetFileName(images(i)) & """ title=""Title " & i & """</imageNode>" + vbNewLine End If Next data += "</images>" sw = New IO.StreamWriter(file) sw.Write(data) MsgBox(data) End If End If Catch ex As Exception MsgBox(ex.ToString) Finally Button1.Enabled = True End Try End Sub





Reply With Quote