[Help]Save Text[Solved]

Posts 1–8 of 8 · Page 1 of 1
[Help]Save Text[Solved]
Alright, so I'm trying to save some entered text to my desktop in the C drive. I have
Code:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Computer.FileSystem.WriteAllText("C:/" & "\keys.txt", Text, True)
    End Sub
but that isn't working. It has an empty text document named keys. Any ideas?
Save TextBox.text as .Txt File

[php]
Imports System.IO
[/php]

Then Button click event (or whereever)

[php]
System.IO.File.WriteAllText("C:\keys.txt",TextBox1 .Text)
[/php]

or

[php]
Dim Tfile1 As String = "C:\keys.txt"
IO.File.WriteAllText(Tfile, TextBox1.Text)
[/php]

If you want to save to your desktop, use SpecialFolderpath


[php]
Dim Deskloc As String
Deskloc = Environment.SpecialFolder.Desktop


Dim Tfile As String = "Deskloc" & "keys.txt"
IO.File.WriteAllText(Tfile, TextBox1.Text)
[/php]

Hope this helps

i want to answer these so bad, but my vb is still craped up
It's still just having a blank text file named keys.
"C:/" & "\keys.txt" = C:/\keys.txt

how should that work o_O?

-------------------------------

Sorry nextgen, but I have to correct you


Quote Originally Posted by Nextgen1
If you want to save to your desktop, use SpecialFolderpath

Code:
 Dim Deskloc As String
        Deskloc = Environment.SpecialFolder.Desktop


        Dim Tfile As String = "Deskloc" & "keys.txt"
        IO.File.WriteAllText(Tfile, TextBox1.Text)
Deskloc will result as "0"

The actual code to get the desktop folder path is the following

Code:
Dim Deskloc As String
        Deskloc = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)


        Dim Tfile As String = "Deskloc" & "keys.txt"
        IO.File.WriteAllText(Tfile, TextBox1.Text)


------------------------------------------------------------

If that's not working for you try the following:


Code:
dim streami as streamwriter

streami = New StreamWriter("C:\test.txt")
   streami.Write(Textbox1.text)
   streami.Close()
I did it off top of head, I don't use special folders often cause there is no reason for me to, But in either case, thanks for the 'Correction"
hmmm if your doing it from with in VB then....

uder public at the top
Code:
Dim var As New System.IO.StreamWriter("\MyText.txt", True)
make a button,
Code:
var.WriteLine()
        var.WriteLine("Name: "& textbox1.text)
var.close()
textbox1 being the box were they placed there name or something...

hope you can use this in some waty...
A. already answered and Solved
B. Read the rules of this section (and Mpgh) no bumping topics over 7 days

- I am not going to close this but it is marked solved, Do Not Post
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us