SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Code to upload zip file from local pc to desired URL

Latest post 05-16-2008 3:52 PM by Sur3ndEr. 1 replies.
  • 05-15-2008 1:08 AM

    Code to upload zip file from local pc to desired URL

    I'm using VB.NET 2005, Framework 2.0 to develop a Windows Application and not web application

    I need to upload a zip file from local PC to a desired URL with the following syntax

    http://localhost:xxxx/tsc/WOSync.do?action=upload&mkey=xxxx&wo[0]=<file>

    How can I do it? The syntax is from a vendor who developed the web app in java.

    This piece of code is in vb6 works, how to convert to vb.net

    'Create an instance of the WinHttpRequest object

    Set WinHttpReq = New WinHttpRequest

     

    'Hard coded URL that HTTP Request will be performed

    'strURL = "http://localhost/retail/eod.do?action=submit"

     

    'Set the zip file's path name

    StrFileName = App.Path & "\ddmmmyyy.zip"

    'Grap the file

    nFile = FreeFile

    Open StrFileName For Binary As #nFile

    strFile = String(LOF(nFile), " ")

    Get #nFile, , strFile

    Close #nFile

    'Assemble an HTTP request.

    WinHttpReq.Open "POST", strURL, False

     

    'Set the header

    WinHttpReq.setRequestHeader "Content-Type", "multipart/form-data; boundary=Xu02=$"

     

    'Assemble the body

    strBody = "--Xu02=$" & vbCrLf & _

    "Content-Disposition: form-data; name=""file""; filename=""" & StrFileName & """" & vbCrLf & _

    "Content-type: file" & vbCrLf & vbCrLf & _

    strFile & vbCrLf & _

    "--Xu02=$--"

     

    'Because of binary zeros, post body has to convert to byte array

    aPostBody = StrConv(strBody, vbFromUnicode)

     

    'Send the HTTP Request.

    WinHttpReq.send aPostBody

  • 05-16-2008 3:52 PM In reply to

    • Sur3ndEr
    • Top 500 Contributor
    • Joined on 12-11-2007
    • Singapore
    • Posts 4

    Re: Code to upload zip file from local pc to desired URL

    Hi,

     If your using .net why dont you use the WebClient class?. The WebClient.UploadFile() Method should help you. Refer to documentation in MSDN

    http://msdn.microsoft.com/en-us/library/36s52zhs.aspx

    Surender.

Page 1 of 1 (2 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems