Below Code will help you download files from internet.
it's very simple code just follow the few steps.
Step 1:Drag two textboxes a two button to ur form.
Step 2 : Just enter the Download Link in Download Location textbox
Step 3 : Just enter the path where u want to save the file.
Note:Download Link path and save as path should be correct.
Step 4 :Just Click the save as Button
Refer the Image Below
VB.NET Code
Private Sub btnSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveAs.Click
Try
If txtLocation.Text.Trim = String.Empty Then
MessageBox.Show("Please Enter the Location from where you want to download", "San Test", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtLocation.Focus()
Exit Sub
ElseIf txtSaveas.Text.Trim.Trim = String.Empty Then
MessageBox.Show("Please Enter the Location to where you want to Save teh File", "San Test", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtSaveas.Focus()
Exit Sub
Else
My.Computer.Network.DownloadFile(txtLocation.Text, txtSaveas.Text & "\Santosh.jpg")
End If
Catch ex As Exception
MessageBox.Show("Please Enter the Correct Path", "San Test", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtSaveas.Focus()
End Try
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
C#.NET Code
private void btnSaveAs_Click(System.Object sender, System.EventArgs e)
{
try {
if (txtLocation.Text.Trim == string.Empty) {
MessageBox.Show("Please Enter the Location from where you want to download", "San Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtLocation.Focus();
return;
} else if (txtSaveas.Text.Trim.Trim == string.Empty) {
MessageBox.Show("Please Enter the Location to where you want to Save teh File", "San Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSaveas.Focus();
return;
} else {
My.Computer.Network.DownloadFile(txtLocation.Text, txtSaveas.Text + "\\Santosh.jpg");
}
} catch (Exception ex) {
MessageBox.Show("Please Enter the Correct Path", "San Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSaveas.Focus();
}
}
private void btnClose_Click(System.Object sender, System.EventArgs e)
{
this.Close();
}