|
-
May 25th, 2012, 10:30 PM
#1
Thread Starter
New Member
Write to path
I'm trying to make a button called "Save" which saves all of the information entered into the textboxes as a .txt document. I'm very notice in this language and I don't know how to do it.
IO.File.WriteAllText
^ That's what I have now.
-
May 25th, 2012, 10:35 PM
#2
Re: Write to path
What exactly do you not understand about the examples of File.WriteAllText that you found on the web? I just Googled and the first result was the MSDN documentation, which is what everyone should read first anyway.
http://msdn.microsoft.com/en-us/library/ms143375.aspx
That includes, amongst other information, a code example. Is there anything in that you're not clear about?
-
May 25th, 2012, 10:41 PM
#3
Re: Write to path
try this:
vb Code:
Public Class Form1
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'save
IO.File.WriteAllLines("c:\example.txt", New String() {TextBox1.Text, TextBox2.Text, TextBox3.Text})
End Sub
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
'open
Dim lines() As String = IO.File.ReadAllLines("c:\example.txt")
If lines.Length <> 3 Then Return
TextBox1.Text = lines(0)
TextBox2.Text = lines(1)
TextBox3.Text = lines(2)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 25th, 2012, 10:49 PM
#4
Re: Write to path
Ah, I missed that it was TextBoxes rather than TextBox. My apologies.
-
May 25th, 2012, 10:49 PM
#5
Thread Starter
New Member
Re: Write to path
The code works sort've. What would I put for c:\example.txt If I just want it to open up the save dialog box as a .txt document on anyones computer.
-
May 25th, 2012, 11:01 PM
#6
Re: Write to path
vb Code:
Public Class Form1
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'save
Dim sfd As New SaveFileDialog With { _
.Title = "Choose file to save to", _
.Filter = "TXT (*.txt)|*.txt|All Files (*.*)|*.*", _
.FilterIndex = 0}
if sfd.showdialog = dialogresult.ok then
IO.File.WriteAllLines(sfd.filename, New String() {TextBox1.Text, TextBox2.Text, TextBox3.Text})
end if
End Sub
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
'open
Dim ofd As New OpenFileDialog With { _
.Title = "Choose file to open", _
.Filter = "TXT (*.txt)|*.txt|All Files (*.*)|*.*", _
.FilterIndex = 0}
if ofd.showdialog = dialogresult.ok then
Dim lines() As String = IO.File.ReadAllLines(ofd.filename)
If lines.Length <> 3 Then Return
TextBox1.Text = lines(0)
TextBox2.Text = lines(1)
TextBox3.Text = lines(2)
end if
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 25th, 2012, 11:05 PM
#7
Re: Write to path
 Originally Posted by Hilt
The code works sort've.
it does everything you asked for in your original question...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 26th, 2012, 08:48 AM
#8
Thread Starter
New Member
Re: Write to path
 Originally Posted by .paul.
 it does everything you asked for in your original question...
'open
Dim lines() As String = IO.File.ReadAllLines("c:\example.txt")
If lines.Length <> 3 Then Return
TextBox1.Text = lines(0)
TextBox2.Text = lines(1)
TextBox3.Text = lines(2)
What root path do I need to put?
Last edited by Hilt; May 26th, 2012 at 09:10 AM.
-
May 26th, 2012, 11:07 AM
#9
Thread Starter
New Member
Re: Write to path
Still have no clue what I'm doing, can anyone give me some insight?
-
May 26th, 2012, 09:06 PM
#10
Re: Write to path
post #6 is the working code.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 26th, 2012, 09:58 PM
#11
Re: Write to path
 Originally Posted by Hilt
'open
Dim lines() As String = IO.File.ReadAllLines("c:\example.txt")
If lines.Length <> 3 Then Return
TextBox1.Text = lines(0)
TextBox2.Text = lines(1)
TextBox3.Text = lines(2)
What root path do I need to put?
You would have to put the path filename of the file you actually want to use. The example code works with the file Example.Txt located in the root of the c drive. Should be pretty clear what you need to do.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|