Public Function Upload(FilePath As String, FileName As String) As Boolean
Dim Url As String = "htt://www.thaicreate.com/fileupload.php"
' Change it to your page name
Dim BytesConfirmedReceived As String = ""
Dim BytesSent As Integer = 0
Dim Ret As Boolean = False
Dim encoding__1 As New ASCIIEncoding()
Try
If File.Exists(Convert.ToString(FilePath & Convert.ToString("\")) & FileName) = False Then
Return True
End If
'FileInfo oInfo = new FileInfo(FilePath + "\\" + FileName);
'BytesSent = Convert.ToInt32(oInfo.Length.ToString());
Url += "?myfile=" + FileName.Trim()
Dim fr As New FileStream(Convert.ToString(FilePath & Convert.ToString("\")) & FileName, FileMode.Open)
Dim r As New BinaryReader(fr)
Dim FileContents As Byte() = r.ReadBytes(CInt(fr.Length))
BytesSent = FileContents.Length
r.Close()
fr.Close()
Dim oRequest As WebRequest = WebRequest.Create(Url)
oRequest.Method = "POST"
oRequest.Timeout = 15000
oRequest.ContentLength = FileContents.Length
Dim oStream As Stream = oRequest.GetRequestStream()
Dim oWriter As New BinaryWriter(oStream)
oWriter.Write(FileContents)
oWriter.Close()
oStream.Close()
Dim oResponse As WebResponse = oRequest.GetResponse()
BytesConfirmedReceived = New StreamReader(oResponse.GetResponseStream(), Encoding.[Default]).ReadToEnd()
oResponse.Close()
If BytesSent.ToString() = BytesConfirmedReceived.Trim() Then
Ret = True
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return Ret
End Function