I am not sure if this will help but this is how I upload file from client's computer without having them to browse the file and click upload button.
Icreated activeX which includesbelow function.
On my web server I have afile called upload.aspx (or it can be upload.jsp,upload.cfm, upload.php etc.) with a <file name= "fileUpload"> object and the code for either uploading to a drive or inserting into database. You can test your page by going to your upload page then do file browse and upload. If that works then you should be good.
@@param strUploadfile = client's directory path eg. c:\image.jpg
@@param url = https://www.blahblah.com/upload.aspx
@@objFileName = "fileUpload"
@@contenttype = "multipart/form-data"
@@ querystring = "userid=1&something=2&...."
Public Function UploadFile(ByVal strUploadfile As String, ByVal url As String, ByVal objFileName As String, ByVal contenttype As String, ByVal querystring As String) As String
If ((fileFormName = Nothing) Or (fileFormName.Length = 0)) Then
fileFormName = "file"
End If
If ((contenttype = Nothing) Or (contenttype.Length = 0)) Then
contenttype = "application/octet-stream"
End If
Dim postdata As String = "?" + querystring
Dim uri As New Uri(url + postdata)
'generate a unique boundary
Dim boundary As String
Dim strTemp As String
strTemp = DateTime.Now.Ticks.ToString("x")
boundary = StrDup(39 - strTemp.Length, "-") & strTemp
'webRequest POST header
Dim webrequest As HttpWebRequest = CType(HttpWebRequest.Create(uri), HttpWebRequest)
webrequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*"
' webrequest.Referer = "add some URL which i can check in cf page to see no body is directly calling it to upload virus"
webrequest.Headers.Add("Accept-Language", "en-us")
webrequest.ContentType = "multipart/form-data; boundary=" + boundary
webrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"
webrequest.KeepAlive = True
webrequest.Headers.Add("Cache-Control", "no-cache")
webrequest.Headers.Add("Cookie", "popunder=yes")
'webrequest.CookieContainer = cookies
webrequest.Method = "POST"
webrequest.ProtocolVersion = HttpVersion.Version10
webrequest.AllowAutoRedirect = False
'MIME Multipart Media Encapsulation
Dim sb As New StringBuilder
sb.Append("--")
sb.Append(boundary)
sb.Append(vbCrLf)
sb.Append("Content-Disposition: form-data; name=""")
sb.Append(fileFormName)
sb.Append("""; filename=""")
sb.Append(Path.GetFileName(strUploadfile))
sb.Append("""")
sb.Append(vbCrLf)
sb.Append("Content-Type: ")
sb.Append(contenttype)
sb.Append(vbCrLf)
sb.Append(vbCrLf)
Dim postHeader As String = sb.ToString()
Dim postHeaderBytes As Byte() = Encoding.ASCII.GetBytes(postHeader)
' Build the trailing boundary string as a byte array
' ensuring the boundary appears on a line by itself
Dim boundaryBytes As Byte() = Encoding.ASCII.GetBytes(vbCrLf & "--" & boundary & vbCrLf)
'open file to upload
Dim fileStream As New FileStream(strUploadfile, FileMode.Open, FileAccess.Read)
'calculate length of POST
Dim length As Long = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length
webrequest.ContentLength = length
'contact server with POST 1.0
Dim requestStream As Stream = webrequest.GetRequestStream()
' Write out header to server
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length)
''Application.DoEvents()
' Write out the file contents to server in chunks of 4K
Dim buffer() As Byte
ReDim buffer(Math.Min(4095, fileStream.Length))
Dim bytesRead = 1 'initialize to any number except 0
While bytesRead <> 0
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead <> 0 Then 'make sure EOF is not reached
requestStream.Write(buffer, 0, bytesRead)
End If
''Application.DoEvents()
End While
' Write out the trailing boundary
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length)
requestStream.Close()
'collect server response & convert to ASCII
Dim responce As WebResponse = webrequest.GetResponse()
Dim s As Stream = responce.GetResponseStream()
Dim sr As New StreamReader(s)
Return sr.ReadToEnd()
End Function