Upload to a server from a VB client 
Author Message
 Upload to a server from a VB client

Hello I want to make a VB client app for uploading files to a web server,
the app must to send the information representing the form structure,
I see one example from Microsoft in VC named poster.exe but i wan to do in
VB

In the server there is a upload component, with the proper page upload.asp



Sat, 08 May 2004 08:13:20 GMT  
 Upload to a server from a VB client
Usually we can use the File element inside the browser and use such server
side component like post acceptor to get the file and save it on the web
server. We can use such method in VB by automate IE and so on.

You can also do the similar things in VB as the poster.exe has done in
VC++. You need to to call some WinInet API functions in Visual Basic
according so that it can post file correctly and use our asp to save it on
the server. You can contact MS support if you have difficulty to do this.

Hope it helps.

Regards,
Robin

This posting is provided AS IS, with no warranties, and confers no rights.



Sun, 09 May 2004 03:55:10 GMT  
 Upload to a server from a VB client
Hey marco,
i now could make it, but it's not really fine how i do it. The problem is
that i make my own boundarys (the files which have to be uploaded are
splitted with boundarys) so here's my code where i send two files a
Word-Document and a XML-File.
- sUrl is the Servlet path
- Dlg is a common dialog control on my form
- sData contains the Data to be uploaded
- H contains additional header information i need for my servlet
- ActiveTransaction contains an integer-value which tells me which
transaction is running, upload, download, login ...and so on... i need that
in the stateChanged event
- sSessionID is my own SessionID which doesn't have to interest u
- have a look at the Mime-Types as well... u have to change them for your
code!

if u have any questions or even a better way to do it, let me know

simon
---------------------------------------------------------
Private Sub btnUpload2_Click()

  If (sSessionID = "-1") Then
    MainForm.Enabled = True
    Exit Sub
  End If

  Dim DocPath As String
  Dim XMLPath As String

  Dlg.Filter = "Word-Dokumente|*.doc"

  Dlg.ShowOpen
  DocPath = Dlg.FileName
  If (DocPath = "") Then
    'Call MsgBox("Mindestens ein Dokument wurde nicht ausgew?hlt!" & Chr(13)
& "Abfrage abgebrochen!", vbCritical)
    Exit Sub
  End If

  Dlg.Filter = "XML-Dokumente|*.xml"

  Dlg.ShowOpen
  XMLPath = Dlg.FileName

  If (XMLPath = "") Then
    'Call MsgBox("Mindestens ein Dokument wurde nicht ausgew?hlt!" & Chr(13)
& "Abfrage abgebrochen!", vbCritical)
    Exit Sub
  End If

  MainForm.Enabled = False
  ActiveTransaction = TT_UPLOAD

  List1.Clear
  RetrData = False

  Dim sUrl As String
    sUrl = ServletURL + sProcTransfer
  'sUrl = urlDebug

  ' HTTP Header vorbereiten
  Dim sBoundary As String
  sBoundary = "-----------------------------7d126e17a04ee"

  Dim H As String
  H = ""
  H = H + "Connection: Keep-Alive" & vbCrLf
  H = H + "Accept-Encoding: gzip, deflate" & vbCrLf
  H = H & "Referer: apage.html" & vbCrLf

  H = H + "Cookie: JServSessionIdroot=" & sSessionID & vbCrLf
  H = H + "Content-Type: multipart/form-data; boundary=" & sBoundary &
vbCrLf

  ' WORD-Dokument auslesen
  Dim sDocData As String
  sDocData = ReadFile(DocPath)

  ' XML Datei auslesen
  Dim sXMLData As String
  sXMLData = ReadFile(XMLPath)

  sBoundary = "--" & sBoundary
  Dim sData As String
  sData = sBoundary & Chr(13) & Chr(10) & "Content-Disposition: form-data;
name=""Filename""; filename=""" & DocPath & """" & Chr(13) & Chr(10)
  sData = sData & "Content-Type: application/msword" & Chr(13) & Chr(10) &
Chr(13) & Chr(10)

  ' Word-Datei
  sData = sData & sDocData & Chr(13) & Chr(10)

  'XML-Header
  sData = sData & sBoundary & Chr(13) & Chr(10)
  sData = sData & "Content-Disposition: form-data; name=""Filename"";
filename=""" & XMLPath & """" & Chr(13) & Chr(10)
  sData = sData & "Content-Type: text/xml"
  sData = sData & Chr(13) & Chr(10) & Chr(13) & Chr(10)

  'XML-Datei
  sData = sData & sXMLData & Chr(13) & Chr(10) & sBoundary & "--" & Chr(13)
& Chr(10)

  Call Inet.Execute(sUrl, "POST", sData, H)
  While (Inet.StillExecuting)
    DoEvents
  Wend

  MainForm.Enabled = True
  ActiveTransaction = TT_NONE
  ' MsgBox ("ende upload")

End Sub



Sun, 09 May 2004 17:12:59 GMT  
 Upload to a server from a VB client


Fri, 19 Jun 1992 00:00:00 GMT  
 Upload to a server from a VB client
Great thanks Simon i try the code and this work perfect,
but i have a question how is the function ReadFile(path)

I see that return a string,
if I want to upload binary files like a gif, jpg u other how is the system ?



Mon, 10 May 2004 03:35:03 GMT  
 Upload to a server from a VB client


Fri, 19 Jun 1992 00:00:00 GMT  
 Upload to a server from a VB client
Thanks for yor help
I wild try yhe code


Mon, 10 May 2004 01:11:48 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Uploading files from the client to the server

2. How do I upload a file from client to server

3. How to upload client files to web server?

4. Upload File Client Server

5. fat client (MSMQ, VB Program) or thin client (ASP page then have Web server use MSMQ)

6. How do I use WFAPI.dll with VB to get client name - Terminal Server client

7. How do I use WFAPI.dll with VB to get client name - Terminal Server client

8. File upload from a vb.net client to a webserver

9. How to upload file from VB client Application ?

10. Upload file to ftp/web server with VB.nET

 

 
Powered by phpBB® Forum Software