Link to home
Start Free TrialLog in
Avatar of npl77
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></>

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

"best way" is subjective...

What version VB?
VB.Net 2005:

        My.Computer.FileSystem.WriteAllText("c:\stuff.xml", "<?xml version=" & Chr(34) & Chr(34) & "1.0" & Chr(34) & Chr(34) & "?>" & vbCrLf & "<v></v>", False)
        My.Computer.FileSystem.WriteAllText("c:\stuff.xml", "<x></x>" & vbCrLf & "<y></>", True)
That probably should be:

        My.Computer.FileSystem.WriteAllText("c:\stuff.xml", "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbCrLf & "<v></v>" & vbCrLf, False)
        My.Computer.FileSystem.WriteAllText("c:\stuff.xml", "<x></x>" & vbCrLf & "<y></y>" & vbCrLf, True)
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()
Avatar of npl77
npl77

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)
Avatar of npl77

ASKER

using vs2005
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial