Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating a file and writing to it

Posted on 2006-10-19
7
Medium Priority
?
200 Views
Last Modified: 2010-04-23
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></>

0
Comment
Question by:npl77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17767278
"best way" is subjective...

What version VB?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17767311
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)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17767355
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)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17767381
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()
0
 

Author Comment

by:npl77
ID: 17767405
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)
0
 

Author Comment

by:npl77
ID: 17767410
using vs2005
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17767450
From a couple comments ago:

    My.Computer.FileSystem.WriteAllText("c:\stuff.xml", "<x></x>" & vbCrLf & "<y></y>" & vbCrLf, True)

The last parameter specifices whether we should append or not.  False makes it overwrite the file.  True makes it append to the end of the file.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question