Library tutorials & articles
Uploading Files with ASP
Introduction
A very frequent question regarding Active Server Pages is "how do I allow a user to upload a file"? Unfortunately, the answer is not particularly straight forward. Active Server Pages itself provides no standard functions, and so you have to rely on either a custom ASP script or a third-party ActiveX DLL.
There are a number of ASP script solutions around, however, due to the non-compiled nature of ASP, combined with its fairly limited commands (even compared to VB), these are extremely inefficient and server intensive. The second solution is an ActiveX DLL. Components such as EZsite UpLoad are available as freeware, however, without access to the source code you are limited in terms of flexibility. Therefore, in this tutorial, we will cover all the necessary steps for creating an ASP page, and a VB ActiveX component for use within your script to enable a file to be uploaded.
|
|
Related articles
Related discussion
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
Run-time error '91'
by crazyidane (0 replies)
-
Problem handling Redirects with MSXML2.XMLHTTP
by brandoncampbell (2 replies)
-
vbinputbox pauses code while it waits on response. How can I reproduce that?
by brandoncampbell (1 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
When i call to component in asp, when i run the uploaddemo.asp, i choose one file, once i press uploading
showing at Invalid class string error. please help me this how to solve this.
Hi:
The component is really good, the code works fine and it has not any problem when is impersonated via MTS.
So, congratulations.
From my ignorance the problem is the Event Blindness: I cannot monitor the upload evolution and was impossible to relate a progress bar.
Please, let me know about any idea or "how to" for the progress bar implementation.
Thanks;
Claudio
Hello,
how i can upload an Excel file which having the file Size 6MB by ASP.NET to the database.
Please Help me !!
How can I debug ASP pages and VB compenets . Ie I have ASP pages in Visual Interdev. These pages talking with few DLLS. I have the VB Source code for these dlls also. Please tell me how can I naviage from ASPs to these class files.. sunnysuku@yahoo.com
What are the components of ASP and VB? Pls help me.
This is a great tool!
Thanks for making this available.
I have a question about ASP, hope you can help me. If I use upload on somebody's website it has to be authenticated with user Id and password. Is there a way I can do that, authencicate users using ASP and allow to upload files, or it is impossible?
In php it is easy, just use connect object. What about asp?
Thank you. And I liked Upload stuff very much.
The save is basically a save as, but if you do not put a file name it will use the current file name.
If you do not put the server.create object at the top of your page you will get this error.
I don't know at what point it will have this problem but I do know if I wrote my stuff like this:
<%option explicit
Dim objUpload
set objUpload = server.createobject("ASPUploadComponent.cUpload")
%>
<!--#include file="../common/functions/dbfunctions.asp"-->
<!--#include file="../common/pageFunctions/header.asp"-->
It would work. If I wrote it like this:
<%option explicit%>
<!--#include file="../common/functions/dbfunctions.asp"-->
<!--#include file="../common/pageFunctions/header.asp"-->
<%
Dim objUpload
set objUpload = server.createobject("ASPUploadComponent.cUpload")
I get the error.
Hope this helps
I had the same error and I asigned permissions of "write" and "read/execute" for my account to the directory where I'm going to save my files.
I made share to web the directory with the same name to the alias and the directory. Maybe this don't care really, but you can test with both.
P.S You must give permissions to the directory that you have defined into the uploadcomplete.asp
Regards
-2147352567 - Unhandled error: Out of memory while uploading a file.The ASP form has a select box with multiple option.
Mr.juyal_pradeep did u get the solution ?
Let me know the solution/ any suggestions.
Thanks,
Sunil B
Hi,
I have compilied the ASPUploadComponent, used regsvr32.exe to register the dll, set IUSRmachinename account access to write to the destination directory as specified in the tutorial, but when I use the upload component in an asp page I get an Permission Denied Error 70 messaage.
I can get the component to work by temporary added the administors group to the IUSRmachinename user, but for obviously can't leave it set like this, PLEASE PLEASE HELP, this is driving me crazy!! - any suggestion would be great
Thanks
thanx very much.when i was searching for help to upload files , i got yoursd and it
works perfectl
This component support "Save as" method?
Please help me.
Hi
I have implimented the asp upload vb based component(dll) its giving me the error
ASPUploadComponent error '80020009'
Unhandled error: Out of memory
so
Is their one who can tell me what are the possible reason and what could be the solution
ok thanks
i will ask them & see
if not i will just have to look for another solution
thanks
yes. if its on a remote server, then you'll have to ask your hosting company to register the dll - but they may not be willing to do this. (at the beginning of the article I wrote "You should be warned that, before we start, not all hosting packages allow you to upload your own ActiveX components.").
on the server?
its a remote server so i probably need to contact my hosting company to do that ?
read dumb blonde below my name & then work from there - he he
am better in cream than i am in code
click start | run, and type
regsvr32.exe "c:\the path to\thedll.dll"
and press enter.
also, see http://www.developerfusion.com/show/1614/
Hi james, thanks for reply
sorry what is regsvr32.exe & where do i get it?
Tonya
did you run regsvr32.exe on the dll file? (you only need the dll to run the component - the rest are source code files)
Hi
I have tried this code but fail with the following error.
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/ASPUploadComponent/ASPFiles/uploadcomplete.asp, line 6
Invalid ProgID.
Line 6 of uploadcomplete.asp is:
'create the ActiveX object
Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")
I downloaded the files as I have no VB editor or experience of Vb code. I did have to resave the Upload class file & save as CUpload.cls as it was called clsupload.cls but left the original there.
can u help & tell me what may be going wrong ??
Thanks Tonya
It's poor solution.
When I upload over 300MB to test, This use over 1200MB memory!
And I cannot stop uploading.
kek..
If a file is uploaded the time it takes for the upload to complete will differ. How is your script going to be cognizant of that? Where in your script does the file that is uploaded effect the progress bar? Do you think you could provide a script that utilizes this ASPUploadComponent? Thanks.
I think it is not quite /2. Close but there is more going on then that.
i got the following error while reading a checkbox value
i used the objUpload.Form("XXX").Value
but it didn't help
please advice
UploadIt (0x80040066) The specified item does not exist
Server object, ASP 0177 (0x800401F3)
Invalid class string
/uploaddemo/uploadcomplete.asp, line 6
My directories are exactly as the examples show.
Running IIS5 on XP Professional and IE 6.0.28
Im getting the following error after pressing upload:
Error 430: Esta clase no admite Automatización o la interfaz esperada.
Im working with pws for Windows 95, and im using my computer as a server and as a client (Learning purposes).
I registered the file ASPUploadComponent.dll with regsvr32.dll, but I cant find any file or property (or anything) named IUSR_COMPUTERNAME, where do i look? any ideas of what might be the problem?
Thanks in advance.
Atte. Ricardo
I really like what you have done however I have a question... I would like to be able to over write the files already in the directory. How do you exclude that error, or catch it in error trapping?
Thanks!
I get the error "permission denied" even after giving the guest account write/read permissions. I want to mention though that I am using my computer as server and client at the same time for test purposes. Is there any piece of software that needs to be installed on my computer?
Thank you.
Hi,
Everytime I try to upload a file...I get the following error message in the uploadcomplete.asp page:
"Error 76: Path not found"
I have already change the path inside the asp page to point to a physical folder. This folder was configured to have Write permission through the IIS.
What could be wrong?
Thanks!
for once code that works first time
hi,
just a question, does your form tag specifies enctype="multipart/form-data"
Example:
<FORM enctype="multipart/form-data" action="reponse.asp" method="Post">
...
</FORM>
It helped for me, i forgot that one...
Hope it will help you
Ya code, and toturial are BEST. BAGUS in Malaysia Language... I've learnt from you...
S'broke. Da ting don't work. FieldExists returns false for all fields. But my form is submitting correctly. The fields and values are there. By forcing an error, IIS shows me my querystring, and it looks fine. The querystring.count is correct, the name value pairs are there, but I still get a false return. Any suggestions?
Here's a sample querystring:
POST Data:
department=plant&startdate=12%2F21%2F02&enddate=12%2F21%2F02&contactname=Mud&email=mud@pit.net&title=Mud+in+your+eye.&message=ieurfvijnqrciqwhefdoWCOINWENC&thefile=F%3A%5Codbcconf.log&submit=Post+mess . . .
Yes. the FileSystemObject has a DeleteFile("c:\thepath\thefile.txt") method.
Is there any delete property to delete an existing file ?
Hi! I happen to see your prob and was trying to look for solutions to it and saw that you actually solved it later but can I have more precise explaining on how you solved it? I am kinda beginner in ASP upload function. Thanks!
my webserver is winme + pws4.0
when I try to open the jpg file in my destination folder in my webserver those files seems to be broken.
I can't open them with any picture tools!
please help me, please!!!
or have ASP installed ...
I downloaded this component recently, It worked great on our development server. But didnt respond on client's server, after removing the on error resume next i got the same error as u got. After a research on the error found that it needs some supporting files. Even after installing supporting files i got the same error. Now i updated the scripting engine with the latest one [5.5] then it worked.
Hope u hav to do the same [
u might u hav done it long back.]
Good luck
Okay so I need to download the .NET SDK and use tblimp.exe to create the type library from the binaries provided.
DUH!
cUpload.cls
When trying to make the dll the compile falls over on cUpload.cls
on the line of code marked in red or the last line if red doens't work.
Is there something I'm missing? I'm using VB6.
Thanks in advance
Option Explicit
'********************
' Purpose: Retrieve a file by HTTP protocol and writes this file
' to a location on the webserver
'********************
'Error Definitions
Private Const ERRFIELDDOESNOTEXIST As Long = vbObjectError + 102
Private MyScriptingContext As ASPTypeLibrary.ScriptingContext
basically, it hasn't regconised the ProgID you've used. This is most likely because you have not registered the DLL using regsvr32.exe
you must change a name of dll in asp page
where you instance component
Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")
bye
Hello there!
I'am trying to run the ASPUploadComponent. Here is my message:
Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.
/uploaddemo/uploadcomplete.asp, line 6
Do you know what i did wrong?
Yours,
Marty
instr for win2k
start -> programs -> admin tools -> com services
iis utilities
components
right click -> new
I think you'd just have to delete the existing file first....
Hi,
Is there a way of overwriting an existing file if it has the same name???
Hi James,
Should I register this COM DLL in Windows 2000 Component Services?
If so, can you show me the steps? I'm especially interested in knowing which Activation Types (Server or Library) I should choose when creating this COM package in Component Services.
When uploading a file over 3 megs in size, I notice my Win2000's CPU utilization shoots up to a constant 100%. It's the call to MyRequest.BinaryRead().
Is there any way to lighten up the CPU load?
Is this required because Unicode carries two bytes or something? Thus, doubling up the file size?
Good job on the upload COM. I'm trying to test it with large files. So far it has worked perfectly with 20meg uploads!
Do you know what is the max file size that this COM will support?
Thanks for the suggestion Aaron - I tried that initally and still no go. Guess its back to ftp
Hi
I have written an vb application for scanning, this file (.tif) has to be uploaded to a remote server. Could anyone give me an idea how to do this without using asp pages.
thanks
Menon
simple answer: no. the ASP script can't get hold of a file on the client's machine that way.....
Hi
Is it posible to use :
<input type="text" name="thefile">
instead of
<input type="file" name="thefile">
in your asp page.
thanks
HarwoorKennedy,
This error: Class does not support Automation or does not support expected interface... is simple to fix, but took me a while to figure out what I was doing wrong. I hope you haven't spent near the time I have on it.
I received the same message when I tried to port just the .DLL over to the NT4.0 server and register it using regsvr32.exe
What I realized is that I needed to have the 2 classes (cFormItem & cUpload) in the same directory as the .DLL when registering it on the server.
The registry registers the 2 classes (ASPUploadComponent.cFormItem & ASPUploadComponent.cUpload) in the HKEYCLASSES and HKEYLOCAL_MACHINE\Software\Classes locations; therefore, the DLL needs to know where the 2 classes (cFormItem & cUpload) are on the local machine. Otherwise, it makes sense that there is no expected interface because the 2 classes were never registered in the registry on the server.
Try porting the entire project, DLL and the 2 classes (cFormItem.cls & cUpload.cls) before registering the DLL.
Hope this helps.
Aaron
Step 1: Insert the following script into the <head> of your page:
<style>
<!--
bar, #barbackground{
position:absolute;
left:0;
top:0;
background-color:blue;
}
barbackground{
background-color:black;
}
-->
</style>
<script language="JavaScript1.2">
//1) Set the duration for the progress bar to complete loading (in seconds)
var duration=5
//2) Set post action to carry out inside function below:
function postaction(){
//Example action could be to navigate to a URL, like following:
//window.location="http://www.dynamicdrive.com"
}
///Done Editing/////////////
var clipright=0
var widthIE=0
var widthNS=0
function initializebar(){
if (document.all){
baranchor.style.visibility="visible"
widthIE=bar.style.pixelWidth
startIE=setInterval("increaseIE()",50)
}
if (document.layers){
widthNS=document.baranchorNS.document.barbackgroundNS.clip.width
document.baranchorNS.document.barNS.clip.right=0
document.baranchorNS.visibility="show"
startNS=setInterval("increaseNS()",50)
}
}
function increaseIE(){
bar.style.clip="rect(0 "+clipright+" auto 0)"
window.status="Loading..."
if (clipright<widthIE)
clipright=clipright+(widthIE/(duration*20))
else{
window.status=''
clearInterval(startIE)
postaction()
}
}
function increaseNS(){
if (clipright<202){
window.status="Loading..."
document.baranchorNS.document.barNS.clip.right=clipright
clipright=clipright+(widthNS/(duration*20))
}
else{
window.status=''
clearInterval(startNS)
postaction()
}
}
window.onload=initializebar
</script>
Step 2: Add the below where you wish the progress bar to appear on the page:
<script language="JavaScript1.2">
if (document.all){
document.write('<div id="baranchor" style="position:relative;width:200px;height:20px;visibility:hidden;">')
document.write('<div id="barbackground" style="width:200px;height:20px;z-index:9"></div>')
document.write('<div id="bar" style="width:200px;height:20px;z-index:10"></div>')
document.write('</div>')
}
</script>
<ilayer name="baranchorNS" visibility="hide" width=200 height=20>
<layer name="barbackgroundNS" bgcolor=black width=200 height=20 z-index=10 left=0 top=0></layer>
<layer name="barNS" bgcolor=blue width=200 height=20 z-index=11 left=0 top=0></layer>
</ilayer>
Hi,
How can add a progress bar in your file upload component.
Amit
When calling a version of the dll on an NT4 Server the following error message is returned:
Class does not support Automation or does not support expected interface
Has anyone experienced this before, if so any ideas as to the cause?
I must admit I didn't test the component with a multiple select box. All I can suggest is opening up the VB source code and debugging to see if the component gets in an endless loop somewhere. Unfortunately, I don't have time to do this at the moment... sorry
I added a select box with multiple select option to the upload form. When I select one option and submit it works fine if I select more than one option I receive this error:
Error Type:
ASPUploadComponent (0x80020009)
Unhandled error: Out of memory
uploadcomplete.asp, line 6
line6 - Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")
Any ideas,
vab9755
hi
i'm also getting problem while submitting form field values with clsupload.asp,can you please help me by sending your code...or can you guide me how to get other field values
bye
srikanth
yeah, it's just the sample page, then. I didn't check the tutorial, though...
hmmm.... is it just the source code that has that incorrect line? The tutorial has
Thanks for that. I shall update the tutorial
Hi James,
you asked me to post any comments about your control here, so here I am
I just checked your code, and, me too, I can't figure out why the FileSize property always return the double filesize. But it seems to be always like that, so why don't you just change the Property Get code from
to
I know, this is not the 'professional's solution', but it'll work for now, at least until you or somebody else has the time to step deep into your code...
Anyway, am I the first and only one who found out about that...?
And now for something completely different: Some other folks posted already that there's a documentation error concerning the object creation: In your asp code, it says
to create the object. Maybe you wanted to rename your project to UploadIt, but then forgot to do so, so actually, the correct code is
You should change that in your example pages in order to avoid more forum messages from people who cannot figure this out by themselves...
HTH
Oliver
a long delay, but maybe it will help someone else with the same problem
You don't specify a file-size limit as such... instead, you check the field that has your file in (such as objUpload.Form("thefile")), and check it's filesize property... ie
if (objUpload.Form("thefile").FileSize > 1000) then
'too big
end if
Hi all,
Can any body help me in writing a script for "downloading a folder from FTP Server (Unix Box) to local system (windows 2000) using vb 6.o"
thankx in advance
SRS
Hi folks,
I'm trying to get the component to upload the file to a share on a different computer in the intranet network. We do not want the files to be saved on the webserver, but on a different machine. It seems to me that just setting the Uploadpath-string in the ASP-code to the unc path of the share would be enough, but for some reason, this doesn't work. I get the message "The folder to upload to doesn't exist." when trying to upload.
I would be very grateful for any advise that would help me solve this problem.
In the code that processes the action for your form
1. use the fso to delete the file like this: in VBScript:
Dim fso
Set fso = CreateObject ("Scripting.FileSystemObject")
Set f = fso.GetFile("C:\Folder\file.ext")
f.Delete
and,
2. with ado run the sql "DELETE FROM tablename WHERE ColumnName=valuetodelete" like this in VBScript:
Dim conn
Dim execdelete
set conn = CreateObject("ADODB.Connection")
conn.Open ("Connection string here")
Set execdelete = conn.execute("DELETE FROM tablename WHERE ColumnName=valuetodelete")
conn.close
set conn = nothing
That should be more than enough to get you started. Check out the excellent downloadable documentation that MS has on their scripting site for more info.
Hi
Say I will use the a file uploader. Some information of the file (like description) goes in a database (sql) and the uploaded file goes in a folder on the server harddisk.
How do I delete a file on the server and its record in the database at the same time when pressing "delete.
Jannike
I figured it out, sorry for not reading the manual carefully. For additional fields in the form, I can use objUpload.Form("Filedname").Value to get the value of the field.
The component works really well.
Now I would like the user to add more information about the file in the upload form. I'd like to have the user choose in a listbox whether the file he wants to upload is a report, a track record, meeting document, so that I can save these search terms in the database.
But since the enc-type in the form is:enctype="multipart/form-data", I can't catch this information with "Request.Form("DocContentType").
How can I solve this problem? Do I have to create two different forms on separate pages? Please help...
I've compiled the code and it works perfectly. However, in searching through it, I can't figure out where the file size limit is set. Can anyone point me in the right direction here? Thanks.
Nevermind - I figured it out. All I needed to do is make sure the name of the VB project is ASPUploadComponent, then make the dll. Everything works great!
I have tried to implement the ASPUploadComponent dll in my ASP project but I believe I haven't registered it correctly. The line of code that reads:
Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")
throws an ASP 0177 error - Invalid ProgID.
Do you know what I am doing wrong?
James:
Yes I knew it was commented out but I searched high and low for that closed parentheses. Remember with beginners such as I and word wrapping the way it is, these little issue can be confusing.
James it works beutiful I want you to know. I set the permissions correctly, I got that down. I am trying to do this though. Pretty much all that is going to be uploaded are jpegs. I would like the confirmation page to show the uploaded jpeg. But for the life of me I just can't get uploadcomplete.asp to show anything but what you have in the original ASP. I tried to put in a HTML link back to the upload.asp. Wouldn't show. I tried to put in <img src="files/<%Request.Item("thefile")%>">. Nothing. No error, no mistake written to the browser. Nothing. It's as if I didn't put anything at all in uploadcomplete.asp.
Can you explain to me why this is and maybe suggest how I can do what I'd like? Do you thing the dll we have made is causing the uploadcomplete.asp to show nothing but what we use in the example? Thanks.
Oh and as a side note did you know that the uploadcomplete.asp is putting a "p" w/o quotes at the end of the ContentType; ex: a jpg uploaded shows:
Content Type: image/pjpeg
Strange don't you think? why pjpeg?
OK... I've got a few things to respond to then... ;-)
-> No closed parentheses <-
You are correct.... I didn't get a syntax error as I had commented the item out... it was just to give the reader an idea of what else they could do. I have corrected that.
-> Folder Permissions <-
There were actually 2 sets of permissions that you needed to set. One was described on page 2, telling you to set Write permissions for the upload directory. The other was on page 7, telling you to give IUSR_MACHINENAME the rights to execute the DLL
-> Object doesn't support this property or method: 'FileExists' <-
That was a typo on your side... ;-) It should have been FieldExists
Regards,
James
<%=strMsg%>
not
<%strMsg%>
George Hester
It is uploading just fine. But in the confirmation I am just getting
<%=objUpload.Form("thefile").Value%>
<%=objUpload.Form("thefile").FileSize%>
<%=objUpload.Form("thefile").ContentType%>
<%=objUpload.Form("description").Value%>
No
<p><%strMsg%><P>
This does not seem to be called:
Description
Else
'add description to the database?
'cConn.Execute ("INSERT INTO mydocs (FileName,Description) VALUES ('" & objUpload.Form("thefile").Value & "','" & objUpload.Form("description").Value
strMsg = "The file was successfully uploaded."
End If
I have disabled caching. Do you think that's an issue?
<%
Option Explicit
'Don't cache the page
Response.AddHeader "Pragma", "No-Cache"
Response.CacheControl = "Private"
%>
In upload.asp
George Hester
Thank you man. sorry for he trouble. It works Marvelous.
Fixed the first error but now I get this one:
Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'FileExists'
/uploaddemo/uploadcomplete.asp, line 18
This comes from:
If objUpload.FileExists("theFile") = False Then
Response.Write "Invalid Post Data"
Response.End
Here is the error I have gotten:
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/uploaddemo/uploadcomplete.asp, line 10
("ASPUploadComponent.cUpload")
I don't think your asp is written correctly. Think?
Further more where exactly is this dll that we made supposed to go? In C:\Inetpub\scripts? And shouldn't the IUSR_MachineName be given read and execute in the entire folder not just on a file in that folder?
Back to the drawing board.
Here is a snippet of the code for uploadcomplete.asp:
Else
'add description to the database?
'cConn.Execute ("INSERT INTO mydocs (FileName,Description) VALUES ('" & objUpload.Form("thefile").Value & "','" & objUpload.Form("description").Value
strMsg = "The file was successfully uploaded."
End If
Look at the part 'cConn.Execute ("INSERT... You will notice there is no closing parentheses for this one I just quoted. That don't seem right?
Apologies for the basic nature of my comment. Does this answer mean that you can open a server based Word document using ASP? How can I use Server.CreateObject so that my web application opens a word template sitting on the same server and transfer text from one asp page to this document. We are using ASP 2.0/SQL7.0/IE3.X to 5.5 and Word97/2000.
You can't open a client-side document using ASP; that would be paramount to giving your script access to each visitors PC....!! When you use Server.CreateObject, it's creating a word object on your server, not the visitors pc... so you won't be able to open their documents.
Yes, using regsvr32.exe. If you are getting a 'permission denied' error, you need to check that you gave IUSR_COMPUTERNAME the rights to access the DLL, as described here
My webbased application using ASP needs to open an existing word document at the client side . Also i need to send some information from the database to this document. Everything must be done with ASP.
I have tried to create an instance of the word application using the CreatObject("Word.Application"). This doesnt work and instead it says, Active X component cannot create object. But when i see in the task manager window, i can actually see the instance of the word created. My browser is IE5.5 SP2.
Is there any other method of invoking Word. Please suggest
should i register the dll?
cFormItem is the class module listed here
How is the cFormItem datatype defined???
This thread is for discussions of Uploading Files with ASP.