DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2008

    upload file and send value using vb.net

    i looking for a way to upload a image or file and a value too using the vb.net so
    far i found this that can send the image i have tested and is fine
    but i can´t understand how put a value to be returned by this:
    $_POST["value"] i have other code that can send the value by post and works fine but
    i need change this code to send post values too
    any one can help me?
    thanks a lot
    Dim filepath As String = IO.Path.Combine(Application.StartupPath, "filename.ext")
    Dim url As String = "http://www.FAKESITE.com/php/Upload/index.php"
    Dim boundary As String = IO.Path.GetRandomFileName
    Dim header As New System.Text.StringBuilder()
    header.AppendLine("--" & boundary)
    header.Append("Content-Disposition: form-data; name=""uploaded_file"";")
    header.AppendFormat("filename=""{0}""", IO.Path.GetFileName(filepath))
    header.AppendLine("Content-Type: application/octet-stream")
    Dim headerbytes() As Byte = System.Text.Encoding.UTF8.GetBytes(header.ToString)
    Dim endboundarybytes() As Byte = System.Text.Encoding.ASCII.GetBytes(vbNewLine & "--" & boundary & "--" & vbNewLine)
    Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create(url)
    req.ContentType = "multipart/form-data; boundary=" & boundary
    req.ContentLength = headerbytes.Length + New IO.FileInfo(filepath).Length + endboundarybytes.Length
    req.Method = "POST"
    Dim s As IO.Stream = req.GetRequestStream
    s.Write(headerbytes, 0, headerbytes.Length)
    Dim filebytes() As Byte = My.Computer.FileSystem.ReadAllBytes(filepath)
    s.Write(filebytes, 0, filebytes.Length)
    s.Write(endboundarybytes, 0, endboundarybytes.Length)
    Last edited by Hack; 03-03-2009 at 12:21 PM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    What kind of value are you looking to send/receive?

Similar Threads

  1. send xml file to web service
    By Bill C in forum XML
    Replies: 2
    Last Post: 06-11-2012, 08:10 PM
  2. validation of File Upload in Struts
    By jenny in forum Java
    Replies: 0
    Last Post: 11-17-2006, 03:33 PM
  3. send xml file to web service
    By Bill C in forum .NET
    Replies: 0
    Last Post: 02-20-2003, 10:35 AM
  4. How can send perameters to a exe file ?
    By Bazy in forum VB Classic
    Replies: 1
    Last Post: 06-26-2001, 08:27 PM
  5. Upload binary file via HTTP
    By Peter in forum Web
    Replies: 0
    Last Post: 02-07-2001, 05:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.