|
-
Mar 23rd, 2003, 01:14 PM
#1
Thread Starter
Frenzied Member
Need new solution !
Hello,
For my project, i need to upload some files to an ASP file on a server(i don't have control on the ASP on the server, it's another guys that does that, because i don't have my security clearance).
At first i wanted to use the web browser control, load a form in it, set it's file value to my document(c:\temp\somefile.xml), but i just found out that i can input the value of a file input with code !
So now what to do, i basically need to pass my document to an ASP file on a server, how can i do this, can i do it with the INET control ? If yes, how would I go about it!
Tx
-
Mar 23rd, 2003, 01:30 PM
#2
Thread Starter
Frenzied Member
ok, i think i need to use the inet control!
but how to upload a file in binary
Inet.Execute([URL],[operation],[inputData],[inputHdrs])
so how would i use that
Inet.Execute "http://www.myserver.com/myfile.asp",,myFileContent,"Content-Type: multipart/form-data; and what else"
what do i need to put in the header and my file content, should it be my file in s string, in a byte array ??
tx again !
-
Mar 23rd, 2003, 02:05 PM
#3
You can use the WebBrowser control, you just need to be a little creative with your solution.
For example, you can send TABS to the WebBrowser window until you're in the File textbox,
then paste the filename/location you want to upload and hit the submit button.
Depending on how you implement this you can have a suprising amount of control over the process.
Here's an example using the vbforums "Search" field:
VB Code:
Option Explicit
Private mbComplete As Boolean
Private Sub cmdWebFile_Click()
If Not fnNavWeb("www.vbforums.com") Then Exit Sub
' Set Focus to the "query" INPUT element
Do
If WebBrowser1.Document.ActiveElement.NodeName = "INPUT" Then
If StrComp(WebBrowser1.Document.ActiveElement.Name, "query", vbTextCompare) = 0 Then Exit Do
End If
' Set Focus to the WebBrowser Control and Tab
WebBrowser1.SetFocus
SendKeys "{TAB}", True
Loop
' Set Focus to the WebBrwoser control
' Copy the text to the clipboard, then
' Paste it into the field.
WebBrowser1.SetFocus
Clipboard.Clear
Clipboard.SetText txtFile.Text
SendKeys "^v", True
' Now Tab to the Submit button and Press it
SendKeys "{TAB}", True
SendKeys "{ENTER}", True
End Sub
Private Function fnNavWeb(ByVal URL As String) As Boolean
Dim tTimer As Single
tTimer = Timer
mbComplete = False
WebBrowser1.Navigate2 URL
Do While Not mbComplete And ((Timer - tTimer) < 30)
DoEvents
Loop
fnNavWeb = mbComplete
End Function
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
mbComplete = True
End If
End Sub
This isn't a File field, however the same principle applies.
-
Mar 23rd, 2003, 02:16 PM
#4
Thread Starter
Frenzied Member
tx
But, i tried to upload a file content to an ASP and write that content to the browser, and it did'nt work, that ASP files works when i use the file input, i think it's because when i sue the input file field, it send the file in a byte array, but if i copy and paste the file content in a text field, it's not a byte array, or so i understand it!
And clearing the Clipboard, it's a risky thing to do, what if the user just copoy something important, i dunno if it's good to clear it!
here's the code i'm using on my ASP file, it's modified for my testing!
VB Code:
<%
Response.Expires = 0
Response.Buffer = true
Private Function stringToByte(toConv)
Dim tempChar
For i = 1 to Len(toConv)
tempChar = Mid(toConv, i, 1)
stringToByte = stringToByte & chrB(AscB(tempChar))
Next
End Function
Dim sPos,ePos,x
Dim separator
toConv=request.BinaryRead(Request.TotalBytes)
separator = MidB(toConv, 1, InstrB(1, toConv, ChrB(13)) - 1)
sPos=169
ePos=InStrB(sPos,toConv,separator)
toConv=MidB(toConv,sPos,ePos-sPos)
Response.ContentType="image/jpeg"
Response.BinaryWrite toConv
%>
the inet control interest me, looks more solid, do you have any info and the inputheaders !!
-
Mar 23rd, 2003, 02:27 PM
#5
You wouldn't paste the content of the file in the field, you would paste the location and filename in the field.
The ASP page will then upload the specified file when it's submitted.
I've used this solution myself and it works fine.
You don't necessarily have to use the Clipboard, you could send the filename directly using the SendKeys command.
-
Mar 23rd, 2003, 02:40 PM
#6
Thread Starter
Frenzied Member
damm, i swear i had tried this, i figured that i could do the same thing if i just put the path in a text input, because the file input is mostly to make more user friendly, with the browse button!
well it will work now, here's what i was using the input my value in my form
VB Code:
With web.Document
If testModeIsOn Then
.Forms("frmUpload").Action = testModeURL
Else
.Forms("frmUpload").Action = strFileToSend(3, intSentFileCpt)
End If
.Forms("frmUpload").manddi_doc.Value = strFileToSend(0, intSentFileCpt) 'this is the file to upload
.Forms("frmUpload").submit
End With
i try it in my code and let you know the result, i just tried in html and it work   
tx a lot man
-
Mar 23rd, 2003, 03:18 PM
#7
Thread Starter
Frenzied Member
Last edited by sebs; Mar 23rd, 2003 at 03:22 PM.
-
Mar 23rd, 2003, 05:42 PM
#8
Thread Starter
Frenzied Member
now i'm in business 
i did the header thing with the webbrowser, works great, don't need a form at all
here's how i built my header for the interested
VB Code:
Const Boundary As String = "---------------------------0123456789012"
Dim bFormData() As Byte
Dim strHeader As String
strHeader = "--" & Boundary & vbCrLf
strHeader = strHeader & "Content-Disposition: form-data; name=""manddi_doc""; filename=""" & strFileToSend(0, intSentFileCpt) & """" & vbCrLf
strHeader = strHeader & "Content-Type: application/upload" & vbCrLf & vbCrLf
strHeader = strHeader & sFormData
strHeader = strHeader & vbCrLf & "--" + Boundary + "--" + vbCrLf
ReDim bFormData(Len(FormData) - 1)
bFormData = StrConv(strHeader, vbFromUnicode)
web.Navigate myURL, , , bFormData, "Content-Type: multipart/form-data; boundary=" + Boundary + vbCrLf
Function GetFile(FileName As String) As String
Dim FileContents() As Byte, FileNumber As Integer
ReDim FileContents(FileLen(FileName) - 1)
FileNumber = FreeFile
Open FileName For Binary As FileNumber
Get FileNumber, , FileContents
Close FileNumber
GetFile = StrConv(FileContents, vbUnicode)
End Function
woks great !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|