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:
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim openFolder As New FolderBrowserDialog
  3.         Dim saveFile As New SaveFileDialog
  4.  
  5.         Dim sw As IO.StreamWriter
  6.  
  7.         Dim path As String
  8.         Dim file As String
  9.         Dim data As String
  10.         Dim images() As String
  11.  
  12.         Try
  13.             Button1.Enabled = False
  14.             openFolder.ShowDialog()
  15.  
  16.             saveFile.FileName = "*.xml"
  17.             saveFile.Filter = "XML File|*.xml"
  18.             saveFile.ShowDialog()
  19.  
  20.             If openFolder.SelectedPath <> "" Then
  21.                 path = openFolder.SelectedPath
  22.  
  23.                 If saveFile.FileName <> "" Then
  24.                     file = saveFile.FileName
  25.  
  26.                     images = IO.Directory.GetFiles(path)
  27.  
  28.  
  29.                     data = "<images directory=""photos/Nuit de la Joke"">" + vbNewLine
  30.                     For i As Integer = 0 To images.Length - 1
  31.                         If IO.Path.GetExtension(images(i)) = ".jpg" Then
  32.                             data += "<imageNode jpegURL=""" & IO.Path.GetFileName(images(i)) & """ thumbURL=""" & IO.Path.GetFileName(images(i)) & """ title=""Title " & i & """</imageNode>" + vbNewLine
  33.                         End If
  34.                     Next
  35.                     data += "</images>"
  36.  
  37.                     sw = New IO.StreamWriter(file)
  38.                     sw.Write(data)
  39.  
  40.                     MsgBox(data)
  41.                 End If
  42.             End If
  43.         Catch ex As Exception
  44.             MsgBox(ex.ToString)
  45.         Finally
  46.             Button1.Enabled = True
  47.         End Try
  48.  
  49.  
  50.     End Sub