473,614 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Upload file without user interaction in vba

Hi there!

I've been digging around looking for a sample on how to upload a file
without user action. I found the following article covering the area:

http://www.motobit.com/tips/detpg_uploadvbaie/
It describes the vba code required to handle a very simple upload
form:

<Form Action=http://127.0.0.30/util/up/free/upload.asp
Method=Post ENCTYPE="multip art/form-data">
<Input Type=File Name=FileField>
<Input Type=Submit>
</Form>

And then the VBA comes here:

'Upload file using input type=file
Sub UploadFile(Dest URL As String, FileName As String, _
Optional ByVal FieldName As String = "File")
Dim sFormData As String, d As String

'Boundary of fields.
'Be sure this string is Not In the source file
Const Boundary As String =
"---------------------------0123456789012"

'Get source file As a string.
sFormData = GetFile(FileNam e)

'Build source form with file contents
d = "--" + Boundary + vbCrLf
d = d + "Content-Disposition: form-data; name=""" + FieldName +
""";"
d = d + " filename=""" + FileName + """" + vbCrLf
d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
d = d + sFormData
d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf

'Post the data To the destination URL
IEPostStringReq uest DestURL, d, Boundary
End Sub

My problem is that my form looks like this:

<form action="upload. asp?
action=upload&t ype=product&ite m=pic1&element= &id=3170&w=1000 &h=1000&maxw=20 0&maxh=5000"
method="post" name="upload" enctype="multip art/form-data">
<input type="hidden" name="type" value="product" >
<input type="hidden" name="item" value="pic1">
<input type="hidden" name="element" value="">
<input type="hidden" name="id" value="3170">
<input type="hidden" name="w" value="1000">
<input type="hidden" name="h" value="1000">
<input type="file" name="picture" size="28">
<input type="submit" value=" upload "">
</form>

So how do I modify the above UploadFile sub, so that it includes all
the fields in the form?

Any help appreciated, because I have to upload 1000+ files 8-()
So any suggestions??

/hco

Jun 23 '07 #1
4 9161
go********@moti x.com wrote:
<Form Action=http://127.0.0.30/util/up/free/upload.asp
Method=Post ENCTYPE="multip art/form-data">
<Input Type=File Name=FileField>
<Input Type=Submit>
</Form>

And then the VBA comes here:

'Upload file using input type=file ...
I find it highly unlikely you are using VBA in ASP. You probably mean
VBScript.
...how do I modify the above UploadFile sub, so that it
includes all the fields in the form?
1. Be prepared to parse *all* of the regions to discover the
non-file form data
2. Use a component
3. Use some other technology, like ASP.NET

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 25 '07 #2
hco
Hi Dave

It is actually VBA, but that is besides the point.

I'm not looking for the asp code to recieve the posted form, but the
code to mimic the post of the form to the server.

In other words, my problem is how to build the sourceform so that it
includes the filestream AND the other fields on the form. So how do I
modify the "build" part below, so it includes the fields on the form
i'm trying to post?
'Build source form with file contents
d = "--" + Boundary + vbCrLf
d = d + "Content-Disposition: form-data; name=""" + FieldName +
""";"
d = d + " filename=""" + FileName + """" + vbCrLf
d = d + "Content-Type: application/upload" + vbCrLf + vbCrLf
d = d + sFormData
d = d + vbCrLf + "--" + Boundary + "--" + vbCrLf

I'm not sure where my question belongs, so If you have any suggestions
for a better place to ask, please let me know ;-)

/hco

Jun 25 '07 #3
hc*@giving.dk wrote:
It is actually VBA, but that is besides the point.

I'm not looking for the asp code to recieve the posted form,
but the code to mimic the post of the form to the server.
Sorry. You can probably understand why I thought that your use of
<form action=path/upload.aspsugge sts an ASP solution is sought.
^^^^^^^^^^

In other words, my problem is how to build the sourceform so
that it includes the filestream AND the other fields on the
form. So how do I modify the "build" part below, so it includes
the fields on the form i'm trying to post?
As I said, parse all of the regions. I cannot overstate the value of the
LiveHTTPHeaders extension for Firefox. Using a test form with three hidden
inputs and a file input, I was able to grab the entire request, including
the following:

Content-Type: multipart/form-data;
boundary=---------------------------29227157615760
Content-Length: 39804
-----------------------------29227157615760
Content-Disposition: form-data; name="Hidden1"

ValueOfHidden1
-----------------------------29227157615760
Content-Disposition: form-data; name="Hidden2"

ValueOfHidden2
-----------------------------29227157615760
Content-Disposition: form-data; name="Hidden3"

ValueOfHidden3
-----------------------------29227157615760
Content-Disposition: form-data; name="File1"; filename="135de 8c6.jpg"
Content-Type: image/jpeg

{encoded binary data}
-----------------------------29227157615760--
So it seems to me you want to discover the region delimiter (or boundary)
and use it to define the regions corresponding to each input. Then start
parsing the regions. I have no doubt it will take work, but the above
example should give you something to work from.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 26 '07 #4
hco
Hi Dave,

Thanks a lot! I think the http header thing will give me the
information I need to be able to construct the form.

I'll get back when i figure out how to construct the formdata.

/hc

Jun 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11753
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
6
3375
by: erez alster | last post by:
first of all i apologetic on my poor english. i want to build an applique and i need to to upload files to my server but i can't used file input... i tought on this hours but i can't get any result. thanks erez.
2
2864
by: Brian Madsen | last post by:
Hey guys, I am currently working on a remote file upload utility from an external server to a local server. Problems I face is: 1)the request server cannot be mapped - ie. i can't secure it by using the IP or somesuch. 2)the process is automatic, no user interaction involved.
2
2378
by: David Hearn | last post by:
I have a webform that I am creating. I need for the user to be able to pass it the path and name of a file on his/her local machine without any interaction. I don't want to have to use the file upload control. This will be an automated process on their end. They should only have to type the url with a path/file name and let it upload the file that they specify (example: They type http://www.mysite.com?FileName=C:\Test\Test.txt and it will...
2
1149
by: vbMark | last post by:
From the URL Query String I'll get the file path like this: private void Page_Load(object sender, System.EventArgs e) { string sFilePath = Request.QueryString; } Now that I have the path how do I upload the file to the server?
8
8765
by: VUNETdotUS | last post by:
My goal is to upload files without submitting the form. I am not looking for the code here but rather a concept. I did a little research and discovered that I can submit a form to an invisible dynamically creeated iframe (to avoid page reloading) and the server page will invoke the client page (where the form is) with window.parent.foo function. However I suspect that this is an old method and I miss some improved ideas. What can one...
1
1706
by: seejay1982 | last post by:
Hi, I am writing an application where I create a temporary file on the client machine and I have to upload this file to a CGI on the server. This needs to be done without the user interaction. I've looked at the FileUpload object but it requires user interaction. Is there any way I can upload the file without the user interaction? Thanks in advance for your help. Seejay
12
2479
by: GuangXiN | last post by:
I want the file upload element disappear, instead of it, I place a text box and a button with my own css defination. but it doesn't work on IE7. What should I do now? <form action="upload.php" method="POST" enctype="multipart/form-data"> <p> <span>Select photo:</span> <input type="file" name="photo" style="display:none;"> <input type="text" name="photoUrl" class="s1" /> <input type="button" class="s2"...
3
1499
by: mp33487 | last post by:
I'm trying to upload/download files programmaticly to a records management system. I have it working fine on my dev machine using vb.net code-behind pages but when I place it on the server when it goes to upload files it (datatable of file paths and data stored in a session var) it errors because the code can't find the files. It seems to be trying to read the file from the server drive not from the client machine. My code is meant to...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.