BP Forums
Download Manger - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: Download Manger (/showthread.php?tid=661)



Download Manger - manishshrestha60 - 09-29-2012

I am look for a code that automatically detects the . format and download the file with the original name kinda like a web browser. And creates the desktop folder where all the files go that you downloaded. I don't don't want to use SaveFileDialog and this code
Code:
SaveFileDialog1.Filter = "JPegImage|*.jpg|.exe|*.exe|.rar|*.rar|.zip|*.zip|.mp3|*.mp3|Bitmap Image|*.bmp|Gif Image|*.giftxt files |.txt|*.txt|All files (*.*)|*.*"""
        SaveFileDialog1.ShowDialog()



Re: Download Manger - brandonio21 - 09-30-2012

I created this little code snippet. Hopefully this is what you were looking for, or something like it:

[code2=vbnet]Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim downloadFilePath As String = "http://brandonsoft.com/Trinity%20Webbrowser.zip?f=11&sid=e4e94d2692431bd601f36f919bfc743e"

Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

If Not (My.Computer.FileSystem.DirectoryExists(desktopPath & "/Downloads")) Then
My.Computer.FileSystem.CreateDirectory(desktopPath & "/Downloads")
End If

'Now we need to simply determine the format of the online file
Dim extensionString As String = System.IO.Path.GetExtension(downloadFilePath)

My.Computer.Network.DownloadFile(downloadFilePath, desktopPath & "/Downloads/download" & GetWebExtension(extensionString))

End Sub

Public Function GetWebExtension(ByVal partialString As String) As String
partialString = partialString.Remove(0, 1)
'Now we need to eliminate any extra chars that aren't alphanumerical
For i As Integer = 1 To partialString.Length Step 1
Dim subString As String = partialString.Substring(0, i)
For Each character As Char In subString
If Not (Char.IsNumber(character) Or Char.IsLetter(character) Or Char.IsWhiteSpace(character)) Then
Return ("." & partialString.Substring(0, i - 1))
End If
Next
Next
Return ("." & partialString)
End Function[/code2]