|
-
Oct 10th, 2002, 06:36 AM
#1
Thread Starter
Hyperactive Member
save text to text file in vb.net? new to it. none of my code works!
save text to text file in vb.net? new to it. none of my code works!
-
Oct 10th, 2002, 06:38 AM
#2
Fanatic Member
Try this:
WriteTextToFile("C:\whatever\FileLOC.txt", "hello")
-
Oct 10th, 2002, 11:50 AM
#3
Frenzied Member
I have a list of the new syntax. And it includes the use of text files. Take a look
~Peter

-
Oct 10th, 2002, 02:25 PM
#4
Thread Starter
Hyperactive Member
Ok.. i need textbox1.text to be saved to a text box..please help..new to vb.net!
-
Oct 10th, 2002, 05:25 PM
#5
Fanatic Member
The way you open the file for write is a bit tricky. Not sure if this is the "right way" but this works for me:
Code:
Try
fs = File.Open(strFileName, FileMode.CreateNew)
Catch ex As Exception
Try
fs = File.Open(strFileName, FileMode.Truncate)
Catch ex2 As Exception
MsgBox(ex.Message)
End Try
End Try
-
Oct 10th, 2002, 05:31 PM
#6
Sleep mode
this will works
Function Save_Text_To_File(ByVal FilePath As String, ByVal FileContent As String, _
Optional ByVal Append As Boolean = False) As Boolean
Dim sw As System.IO.StreamWriter
Try
sw = New System.IO.StreamWriter(FilePath, Append)
sw.Write(FileContent)
Return True
Catch e As Exception
Return False
Finally
If Not sw Is Nothing Then sw.Close()
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call Save_Text_To_File("c:\test.txt", TextBox1.Text, True)
End Sub
-
Oct 10th, 2002, 05:34 PM
#7
Fanatic Member
What if you don't want to Append though?
-
Oct 10th, 2002, 05:37 PM
#8
Sleep mode
then It must be set = false
-
Oct 11th, 2002, 06:23 AM
#9
Lively Member
Would it be easiest to do this?
to copy the text box to a richtextbox and use savefile?
richtextbox1.text=textbox1.text
richtextbox1..SaveFile"c:\text.txt",RichTextBoxStreamType.PlainText)
-
Oct 11th, 2002, 04:41 PM
#10
Sleep mode
the function would be direct solution. (I don't know if Iamthewalrus15's way work out)
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
|