tags:

views:

72

answers:

1

I'm trying to create an app launcher in vb.net but I do not know how to save files. Save files like the one that is executed when you run a setup for an application wherein the setup will save the application files on program files folder. I'm not trying to create a vb.net setup, because I want to run my program as portable. What I want the program to do is to place the files in their appropriate location when the user clicks a button Here's my current code:

    Public Class Nircmd

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'shutdown
    System.Diagnostics.Process.Start("E:\Documents and Settings\Rew\Desktop\Shutdown.lnk")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    'monitor off
    System.Diagnostics.Process.Start("E:\Documents and Settings\Rew\Desktop\Monitor Off.lnk")

End Sub

End Class

-Of course it won't work if the path doesn't contain the file specified. So I want to place another button that would do just that(to save the files specified in the desired folder. A simple syntax will do. Please

+2  A: 

I don't quite understand, but I'll take a shot.

This will check to see if C:\foo\somefile.txt exists, and if it doesn't, create it and write some text:

If Not System.IO.File.Exists("C:\foo\somefile.txt") = True Then
    Dim file As System.IO.FileStream
    file = System.IO.File.Create("C:\foo\somefile.txt")
    file.Close()
End If
My.Computer.FileSystem.WriteAllText("C:\foo\somefile.txt", "Some text")

If you want to copy or move a file, I think you'll want something like:

System.IO.File.Copy("C:\foo\somefile.txt", "C:\bar\somefile.txt")

or

System.IO.File.Move("C:\foo\somefile.txt", "C:\bar\somefile.txt")
Auguste