You are on page 1of 5

How to Upload a File From One Computer to Other

Computer Using VB.Net


Posted: November 16, 2012 in VB.Net

0
directly
go
to
the
cases,
case: we will create an application using VB for uploading a file to server,which a file will be
putting in the path : C:\xampp\htdocs\coba\upload\(name of file)=>in the servers computer.
for more details please observe and understand the picture below.

does you have understand the picture above ? if not yet there is an explanation for the case.
application which built with VB will be run on 2 clients computer whereas a database will be
putting on server.
for the first create a database on XAMPP along the table and give the name for database :
sharedata, tabel : upload,for the column will be details with a picture below.

do share a database so that both the client computer can be access and give a full access(just
optional)if you do not know how to share a database.this is a link for database
process
: https://maridibaca.wordpress.com/2012/10/20/share-database-mysql-dengan-vb2010/
lets will go to application,create a form like image below and change property name as in the
picture below

in this discussion I will focus to how to upload file from clients computer to servers path
and display a data from file which uploaded to datagridview, for group and download button
not covered.
create connection module to database server (192.168.1.1)
Imports System.Data.Odbc
Module Module1
Public conn As OdbcConnection
Public cmd As OdbcCommand
Public str As String
Public ds As DataSet
Public da As OdbcDataAdapter
Public rd As OdbcDataReader
Public Sub koneksi()
'192.168.1.1 adalah ip dari server
'nanda adalah nama user baru yang diberikan hak akses sama dengan root
'konektor menggunakan odbc
str = "Driver={MySQL ODBC 5.1
Driver};Database=sharedata;Server=192.168.1.1;uid=nanda"
conn = New OdbcConnection(str)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
End Sub
End Module

enter the code below to form1/ menuutama (a name in my form),do the sharing uploads
folder before (in the servers computer) as a picture below, give a level permission =>
Read/Write and copy folder link that was shared

this is a link picture that will copied

Imports System.Data
Imports System.Data.Odbc
Imports System.IO
Imports Microsoft.VisualBasic.Devices
Public Class menuutama
Private Sub menuutama_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'memanggil koneksi untuk di buka
Call koneksi()
Call tampilkan()
End Sub
Sub aturkolom()
DataGridView1.Columns(0).Width = 60
DataGridView1.Columns(1).Width = 145
End Sub
Sub tampilkan()
da = New OdbcDataAdapter("select nama from upload", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "upload")
DataGridView1.DataSource = (ds.Tables("upload"))
DataGridView1.ReadOnly = True
DataGridView1.Refresh()
Call aturkolom()
End Sub
Sub bersihkan()
TextBox1.Text = ""
TextBox2.Text = ""
Search.Focus()
End Sub
Private Sub Upload_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Upload.Click

Try
'\\NANDA-PC\upload\ adalah link dari folder upload yang di share
System.IO.File.Move(TextBox1.Text, "\\NANDA-PC\upload\" & TextBox2.Text &
"")
cmd = New OdbcCommand("insert into upload
(id,username,location,nama,id_user)
values('','nanda','C:/xampp/htdocs/coba/upload/" & TextBox2.Text & "','" &
TextBox2.Text & "','1')", conn)
cmd.ExecuteNonQuery()
MsgBox("berhasil")
Call bersihkan()
Catch ex As Exception
MessageBox.Show("Accessed" & vbCrLf & ex.Message)
End Try
End If
End Sub
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Search.Click
With Me.OpenFileDialog1
.FileName = "nama file"
.Filter = "All File(*.*)|*.*|JPG(*.jpg)|*.jpg"
.FilterIndex = 1
.InitialDirectory = "D:\"
If .ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = .FileName
End If
End With
End Sub
Private Sub Refres_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Refres.Click
Call tampilkan()
End Sub
Private Sub Home_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Home.Click
DataGridView1.Visible = True
Refres.Visible = True End Sub
End Class

after it all run an application, dont forget to setting IP like a picture above, turn off
firewall.the result of program like a picture below

explanation:

uploads folder is folder that author created to unify file that was uploaded, the
path C:\xampp\htdocs\coba\upload

add OpenFileDialog in our form

You might also like