Solved

Send data to asp page

Posted on 2004-10-05
4
166 Views
Last Modified: 2010-05-02
i am using this function

Private Sub upload(filename As String)

    On Error GoTo ErrHandler

    Dim aPostData() As Byte
    Dim vPostData As Variant
    Dim vUrl As Variant
    Dim vHeaders As Variant
    Dim strText As String
    Dim strContentHeader As String
    Dim strBody As String
    Dim nFile As Integer

    strContentHeader = "Content-Type: text/plain" & vbCrLf
    'read the whole file
    nFile = FreeFile
    Open filename For Binary As #nFile
    strText = String(LOF(nFile), " ")
    Get #nFile, , strText
    Close #nFile
    'http header
    vHeaders = "Content-Type: multipart/form-data, boundary=AaB03x" & vbCrLf
    'assemble the body. send one field and one file
    strBody = ""
   
    strBody = strBody & "--AaB03x" & vbCrLf
    strBody = strBody & "Content-Disposition: attachment; name=""FILE1""; filename=""" & filename & """" & vbCrLf
    strBody = strBody & strContentHeader & vbCrLf
    strBody = strBody & strText & vbCrLf
    strBody = strBody & "--AaB03x--"
    'must convert to byte array
    aPostData = StrConv(strBody, vbFromUnicode)
    vPostData = aPostData
    'post to...
    vUrl = "http://........................asp"
    'Do it!
    WebBrowser1.Navigate vUrl, 0, "", vPostData, vHeaders
    Exit Sub
ErrHandler:
    Err.Clear
    upload filename
    Close #nFile
    Exit Sub
End Sub


it works just like it i had a form like the following

<FORM name="send" method="post" encType="multipart/form-data" action="http://....asp">
      <INPUT type="File" name="File1" size="20">
      <INPUT type="Submit" value="Upload">
</FORM>


it works fine

but i want to add a field to it

like the form

<FORM name="send" method="post" encType="multipart/form-data" action="http://....asp">
      <INPUT type="hidden" name="firstname" value="gerald">
                 <INPUT type="File" name="File1" size="20">
      <INPUT type="Submit" value="Upload">
</FORM>

thanks in advance
0
Comment
Question by:gezzuzz
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 230 total points
ID: 12233012
The format will go something such as the below...

(START)
-----------------------------7d428027f101d8
Content-Disposition: form-data; name="File1"; filename="c:\myfile.txt"
Content-Type: text/plain

myfile.txt's data
-----------------------------7d428027f101d8
Content-Disposition: form-data; name="firstname"

gerald
-----------------------------7d428027f101d8--
(END)


This is not a regular method for form values being submitted so the ASP script will have to parse for both the file-data and the input values.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12537833
ping
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now