read XML file, create/modify folders, add files to each folder
Need some help modifing my code to work correctly. I'm Stumped.
What I would like to do is read a basic xml filed called web.sitemap. While walking through the xml file, create a directory for each node and childnode. The "title" attribute will be the name of the directory to be created. The "url" attribute is the location of the final directory that needs to be created. Once the directory has been created, copy 4 files to that folder. Then repeat process until the xml file has been completed.
I've attached some code that is somewhat working. The problem with the code is that it creates all the directories within the same folder. Then copies the 4 files to each folder. If anyone has a better way, please suggest.....
A small example of what my xml file looks like this:
Dim xmlr As XmlTextReader Try xmlr = New XmlTextReader("d:\<removed for security reasons>\web.sitemap") xmlr.Read() While Not xmlr.EOF xmlr.Read() If Not xmlr.IsStartElement Then Exit While End If Dim oTitle As String, rTitle As String oTitle = xmlr.GetAttribute("title") Dim dirName As String Dim dir As String = Request.PhysicalApplicationPath rTitle = Replace(oTitle, " ", "_") dirName = rTitle xmlr.Read() Dim dirstring As String dirstring = dir + "products\" & dirName If Directory.Exists(dirstring) Then Response.Write(dirstring & " - ALREADY CREATED!<br>") Else Directory.CreateDirectory(dirstring) Response.Write(dirstring & " - Created!<br>") End If Dim fName1 As String = "Default.aspx" Dim fName2 As String = "DisplayProducts1.aspx" Dim fName3 As String = "Default.aspx.vb" Dim fName4 As String = "DisplayProducts1.aspx.vb" File.Copy("d:\<removed for security reasons>\cfolder\" & fName1, dir + "products\" & dirName & "\" & fName1) File.Copy("d:\<removed for security reasons>\cfolder\" & fName2, dir + "products\" & dirName & "\" & fName2) File.Copy("d:\<removed for security reasons>\cfolder\" & fName3, dir + "products\" & dirName & "\" & fName3) File.Copy("d:\<removed for security reasons>\cfolder\" & fName4, dir + "products\" & dirName & "\" & fName4) End While xmlr.Close() Catch ex As Exception Response.Write(ex.Message) End Try