Dim sb As New System.Text.StringBuilder
sb.Append("--")
sb.Append(boundary)
sb.Append(ControlChars.Cr + ControlChars.Lf)
sb.Append("Content-Disposition: form-data; name=""")
sb.Append(fileFormName)
sb.Append("""; filename=""")
sb.Append(Path.GetFileName(uploadfile))
sb.Append("""")
sb.Append(ControlChars.Cr + ControlChars.Lf)
sb.Append("Content-Type: ")
sb.Append(contenttype)
sb.Append(ControlChars.Cr + ControlChars.Lf)
sb.Append(ControlChars.Cr + ControlChars.Lf)

Dim postHeader As String = sb.ToString()
Dim postHeaderBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(postHeader)
Dim boundaryBytes As Byte() = System.Text.Encoding.ASCII.GetBytes((ControlChars.Cr + ControlChars.Lf + "--" + boundary + ControlChars.Cr + ControlChars.Lf))
Dim fileStream As New FileStream(uploadfile, FileMode.Open, FileAccess.Read)
Dim length As Long = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length
webrequest.ContentLength = length

Dim requestStream As Stream = webrequest.GetRequestStream()

requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length)

Dim buffer() As Byte = New [Byte]() {}