Question : Create File from count

I have a sub below that counts the files in a directory.

I now need to take that count and use it to build an xml file.

I have the "build" working but need to write the image tag line for whatever (i) timnes there is.

 Public Sub buildXMLFile()
        Dim str As String = "" _
            & vbCrLf & "" _
            & vbCrLf & "   " _
            & vbCrLf & "      " _  THIS LINE NEEDS TO BE REPEATED (i) TIMES
            & vbCrLf & "  
" _
            & vbCrLf & "
"
        Dim w As System.IO.StreamWriter = New System.IO.StreamWriter(System.IO.File.Open(Server.MapPath("~/sss.xml"), IO.FileMode.Create))
        w.Write(str)
        w.Close()
Code Snippet:
1:
2:
3:
4:
Public Sub CountFiles1()
        Dim i As Integer = Directory.GetFiles(Server.MapPath("~/images/")).Length
        lblCount.Text = "There are " & i.ToString & " files in the directory"
    End Sub

Answer : Create File from count

There's a slightly better way to do this using the actual files instead of a counting loop, which might produce unexpected results.

Try this - we can always change it if necessary...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Dim fi() As FileInfo = New DirectoryInfo(Server.MapPath("~/images/")).GetFiles
		Dim sb As New StringBuilder
		sb.AppendLine("")
		sb.AppendLine("")
		sb.AppendLine("")
		For Each File In fi
			sb.AppendLine("")
		Next
		sb.AppendLine("")
		sb.AppendLine("")
		Dim w As System.IO.StreamWriter = New System.IO.StreamWriter(System.IO.File.Open(Server.MapPath("~/sss.xml"), IO.FileMode.Create))
		w.Write(sb.ToString)
		w.Close()
Random Solutions  
 
programming4us programming4us