npl77
asked on
Creating a file and writing to it
Whats the best way to create a file named "stuff.xml" then write these 2 lines:
<?xml version=""1.0""?>
<v></v>
then append these lines
<x></x>
<y></>
<?xml version=""1.0""?>
<v></v>
then append these lines
<x></x>
<y></>
VB.Net 2005:
My.Computer.FileSystem.Wri teAllText( "c:\stuff. xml", "<?xml version=" & Chr(34) & Chr(34) & "1.0" & Chr(34) & Chr(34) & "?>" & vbCrLf & "<v></v>", False)
My.Computer.FileSystem.Wri teAllText( "c:\stuff. xml", "<x></x>" & vbCrLf & "<y></>", True)
My.Computer.FileSystem.Wri
My.Computer.FileSystem.Wri
That probably should be:
My.Computer.FileSystem.Wri teAllText( "c:\stuff. xml", "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbCrLf & "<v></v>" & vbCrLf, False)
My.Computer.FileSystem.Wri teAllText( "c:\stuff. xml", "<x></x>" & vbCrLf & "<y></y>" & vbCrLf, True)
My.Computer.FileSystem.Wri
My.Computer.FileSystem.Wri
For earlier .Net versions:
Dim sw As New System.IO.StreamWriter("c: \stuff.xml ", False)
sw.Write("<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbCrLf & "<v></v>" & vbCrLf)
sw.Close()
Dim sw2 = New System.IO.StreamWriter("c: \stuff.xml ", True)
sw2.Write("<x></x>" & vbCrLf & "<y></y>" & vbCrLf)
sw2.Close()
Dim sw As New System.IO.StreamWriter("c:
sw.Write("<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbCrLf & "<v></v>" & vbCrLf)
sw.Close()
Dim sw2 = New System.IO.StreamWriter("c:
sw2.Write("<x></x>" & vbCrLf & "<y></y>" & vbCrLf)
sw2.Close()
ASKER
i must be able to append on a button click append the( <x>, <y<>). I was using a streamwriter but it doesnt work
xmlWriter = New StreamWriter(xmlPath)
xmlWriter.Write("<?xml version=""1.0""?>" & vbCrLf )
then on the button click:
xmlWriter.Write(xml)
xmlWriter = New StreamWriter(xmlPath)
xmlWriter.Write("<?xml version=""1.0""?>" & vbCrLf )
then on the button click:
xmlWriter.Write(xml)
ASKER
using vs2005
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What version VB?