upload file and send value using vb.net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: upload file and send value using vb.net

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    164

    upload file and send value using vb.net

    hi,
    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
    Code:
    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()
    header.AppendLine("Content-Type: application/octet-stream")
    header.AppendLine()
    
    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)
    s.Close()
    Last edited by Hack; 03-03-2009 at 12:21 PM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What kind of value are you looking to send/receive?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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