2

I have looked almost everywhere on the internet and I cannot find a way to download a file from the internet into a specific folder that works with VB.NET 2010. I would like to download a file called, for instance, example.txt, and download it into, for example, %HOMEDRIVE%%HOMEPATH%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup so that it will run automatically at system startup. All help is appreciated

pnuts
  • 58,317
  • 11
  • 87
  • 139

2 Answers2

3

Guessing something based on...

Using webClient = New WebClient()
  Dim bytes = webClient.DownloadData("http://www.google.com")

  File.WriteAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyFileName.ext"), bytes)
End Using

As for the startup, VB.NET has a pretty ease way to add Registry keys...

My.Computer.Registry.SetValue

To set something like HKEY_CURRENT_USER\Software\Microsoft\CurrentVersion\Run

UPDATE

How to: Create a Registry Key and Set Its Values in Visual Basic

http://msdn.microsoft.com/en-us/library/cy6azwf7(v=VS.100).aspx

Chris Baxter
  • 16,083
  • 9
  • 51
  • 72
0

I would suggest using WebClient.DownloadFile. Use Environment.SpecialFolder.Startup to get the path to save the file.

Sub Main()

    Using wc As New WebClient()
        Dim startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
        wc.DownloadFile("http://MyDomain.com/MyFile.txt", Path.Combine(startupPath, "test.txt"))
    End Using

End Sub
Brian
  • 37,399
  • 24
  • 94
  • 109