Question[Help]Save Text to Desktop[Solved]

Posts 1–9 of 9 · Page 1 of 1
[Help]Save Text to Desktop[Solved]
How do you make an option in vb.net to save text to desktop?
did you google yet?...

google for streamwriter.
Here you go. Thank me please

Change the user name to yours

[php]Imports System.IO
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim TextFile As New StreamWriter("c:\Users\Zack\Desktop\test.txt")
TextFile.WriteLine("Text here")
' make more of these TextFile.WriteLine("Text here")to get more lines.
TextFile.Close()



End Sub
End Class[/php]
Professionally and commercially you would want to do this without hard-coding the direct path , because if a 3rd party uses it, they will not be able to save the txt file to the desktop path.

Use

[php]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim DesktopPath As String = Environment.GetFolderPath(Environment.SpecialFolde r.DesktopDirectory)

Dim TextFile As New StreamWriter(DesktopPath & test.txt")
TextFile.WriteLine("Text here") ' or textbox.text
' make more of these TextFile.WriteLine("Text here")to get more lines.
TextFile.Close()


End Sub
[/php]

A good note to all developers is to remember that vb.net allows you to access user folders as special folders without hardcoding the user name and path

[php]
Environment.SpecialFolder.
[/php]

This will give you access to

Cookies
Desktop
My Pictures
My Documents
History
etc
etc

Without the need for the username

added to code snippets vault post 1


this will allow saving to anyones desktop


You copied some of my code nextgen . LOL
Its MSDN Standard, But yes I part of your above example to make sense of the prior :d
Woot Nextgen1 used one of my examples WOOT. HAH thanks
OR

[php] My.Computer.FileSystem.WriteAllText(My.Computer.Fi leSystem.SpecialDirectories.Desktop & "\filename.txt", "Text here...", False)
[/php]
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us