Library tutorials & articles

Uploading Files with ASP

Source Code (2)

Now add the following code to cFormItem. This makes up a form field object.

Option Explicit

'Error Definitions
Private Const ERR_FILESIZE_NOT_ALLOWED As Long = vbObjectError + 103
Private Const ERR_FOLDER_DOES_NOT_EXIST As Long = vbObjectError + 104
Private Const ERR_FILE_ALREADY_EXISTS As Long = vbObjectError + 105
Private Const ERR_FILE_TYPE_NOT_ALLOWED As Long = vbObjectError + 106

Private varFileData As Variant
Private cData       As Collection

'*****************************************************************
' Add()
' Purpose:  Adds an item to the field collection
' Inputs:   strKey   -- the item's key
'           strValue     -- string containing the value
'*****************************************************************
Friend Sub Add(ByVal strKey As String, ByVal strValue As String)
    cData.Add strValue, strKey
End Sub

'*****************************************************************
' FileData()
' Purpose:  Sets the contents of a file
' Inputs:   varContent   -- the content of the file
'*****************************************************************

Friend Property Let FileData(varContent As Variant)
    varFileData = varContent
End Property

'*****************************************************************
' Properties
' Purpose:  Returns various public values
'*****************************************************************
Public Property Get Value() As String
    Value = GetVal("FileName")
End Property
Public Property Get FileSize() As String
    FileSize = GetVal("FileLen")
End Property
Public Property Get Name() As String
    Name = GetVal("Name")
End Property
Public Property Get ContentType() As String
    ContentType = GetVal("ContentType")
End Property
Public Property Get IsFile() As Boolean
    IsFile = Exists("FileName")
End Property

'*****************************************************************
' Private Functions
'*****************************************************************

Private Sub Class_Initialize()
    Set cData = New Collection
End Sub
Private Function GetVal(ByVal strKey As String) As String
    If Exists(strKey) Then
        GetVal = cData(strKey)
    Else
        GetVal = cData("Value")
    End If
End Function
Private Function Exists(ByVal strKey As String) As Boolean
    Dim strDummy As String
    On Error Resume Next
    strDummy = cData(strKey)
    If Err = 0 Then Exists = True
End Function


'*****************************************************************
' SaveFile()
' Purpose:  Saves the form entry to a file (if it is one)
' Inputs:   strUploadPath   -- string containing the directory to upload to
'           strFileName     -- string containing the filename
'           strExcludeFileExtensions -- file extensions to exclude
'*****************************************************************
Public Sub SaveFile(ByVal strUploadPath As String, ByVal strFileName As String, Optional ByVal strExcludeFileExtensions As String = "", Optional ByVal lMaxByteCount As Long = 0)
    'we can only save files...
    If IsFile = False Then Exit Sub
    If strFileName = "" Then strFileName = cData("FileName")
    'Check to see if file extensions are excluded
    If strExcludeFileExtensions <> "" Then
        If ValidFileExtension(strFileName, strExcludeFileExtensions) Then
            Err.Raise ERR_FILE_TYPE_NOT_ALLOWED, "ASPUploadComponent", "It is not allowed to upload a file containing a [." & GetFileExtension(strFileName) & "] extension"
        End If
    End If

    'Check for maximum bytes allowed
    If Not lMaxByteCount = 0 Then
        If lMaxByteCount < FileSize() Then
            Err.Raise ERR_FILESIZE_NOT_ALLOWED, "ASPUploadComponent", "File size exceeds maximum size specified"
        End If
    End If

    WriteFile strUploadPath, strFileName
End Sub

'*****************************************************************
' WriteFile()
' Purpose:  Writes the uploaded file to a given directory
' Inputs:   strUploadPath   -- string containing the directory to upload to
'           strFileName     -- string containing the filename
'*****************************************************************
Private Sub WriteFile(ByVal strUploadPath As String, ByVal strFileName As String)

On Error GoTo WriteFile_Err

    'Variables for file
    Dim fs As Scripting.FileSystemObject
    Set fs = New Scripting.FileSystemObject
   
    Dim sFile As Object
   
    If Not Right(strUploadPath, 1) = "\" Then
        strUploadPath = strUploadPath & "\"
    End If
   
    If Not fs.FolderExists(strUploadPath) Then
        Err.Raise ERR_FOLDER_DOES_NOT_EXIST, "ASPUploadComponent", "The folder to upload to doesn't exist"
    End If
   
    If fs.FileExists(strUploadPath & strFileName) Then
        Err.Raise ERR_FILE_ALREADY_EXISTS, "ASPUploadComponent", "The file [" & strFileName & "] already exists."
    End If
   
    'Create file
    Set sFile = fs.CreateTextFile(strUploadPath & strFileName, True)
   
    'Write file
    sFile.Write varFileData
   
    'Close File
    sFile.Close
   
    Set sFile = Nothing
    Set fs = Nothing

    Exit Sub

WriteFile_Err:

    Err.Raise Err.Number

End Sub
'*****************************************************************
' ValidFileExtension()
' Purpose:  Checks if the file extension is allowed
' Inputs:   strFileName -- the filename
'           strFileExtension -- the fileextensions not allowed
' Returns:  boolean
'*****************************************************************

Private Function ValidFileExtension(ByVal strFileName As String, Optional ByVal strFileExtensions As String = "") As Boolean

    Dim arrExtension() As String
    Dim strFileExtension As String
    Dim i As Integer
   
    strFileExtension = UCase(GetFileExtension(strFileName))
   
    arrExtension = Split(UCase(strFileExtensions), ";")
   
    For i = 0 To UBound(arrExtension)
       
        'Check to see if a "dot" exists
        If Left(arrExtension(i), 1) = "." Then
            arrExtension(i) = Replace(arrExtension(i), ".", vbNullString)
        End If
       
        'Check to see if FileExtension is allowed
        If arrExtension(i) = strFileExtension Then
            ValidFileExtension = True
            Exit Function
        End If
       
    Next
   
    ValidFileExtension = False

End Function


'*****************************************************************
' GetFileExtension()
' Purpose:  Returns the extension of a filename
' Inputs:   strFileName     -- string containing the filename
'           varContent      -- variant containing the filedata
' Outputs:  a string containing the fileextension
'*****************************************************************

Private Function GetFileExtension(strFileName) As String

    GetFileExtension = Mid(strFileName, InStrRev(strFileName, ".") + 1)
   
End Function

Comments

  1. 19 Apr 2005 at 07:05

    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.

  2. 12 Apr 2005 at 22:06

    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

  3. 03 Dec 2004 at 08:51


    Hello,


           how i can upload an Excel file which having the file Size 6MB by ASP.NET to the database.

  4. 01 Apr 2004 at 02:19

    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

  5. 01 Mar 2004 at 22:11

    What are the components of ASP and VB? Pls help me.

  6. 01 Mar 2004 at 19:23

    This is a great tool!


    Thanks for making this available.

  7. 10 Nov 2003 at 21:26

    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.

  8. 05 Nov 2003 at 16:37

    The save is basically a save as, but if you do not put a file name it will use the current file name.

  9. 05 Nov 2003 at 13:52

    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


  10. 12 Sep 2003 at 13:44

    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


  11. 01 Sep 2003 at 04:57

    -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

  12. 15 Jul 2003 at 21:01

    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 IUSR
    machinename 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

  13. 30 Jun 2003 at 03:48

    thanx very much.when i was searching for help to upload files , i got yoursd and it
    works perfectl



  14. 28 May 2003 at 11:30

    This component support "Save as" method?
    Please help me.

  15. 18 Apr 2003 at 09:57

    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

  16. 24 Mar 2003 at 11:22

    ok thanks


    i will ask them & see


    if not i will just have to look for another solution


    thanks

  17. 24 Mar 2003 at 11:06

    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.").

  18. 24 Mar 2003 at 11:02

    on the server?


    its a remote server so i probably need to contact my hosting company to do that ?

  19. 24 Mar 2003 at 10:56

    read dumb blonde below my name & then work from there - he he


    am better in cream than i am in code

  20. 24 Mar 2003 at 10:56

    click start | run, and type


    regsvr32.exe "c:\the path to\thedll.dll"


    and press enter.

  21. 24 Mar 2003 at 10:55
  22. 24 Mar 2003 at 10:55

    Hi james, thanks for reply


    sorry what is regsvr32.exe & where do i get it?


    Tonya

  23. 24 Mar 2003 at 10:49

    did you run regsvr32.exe on the dll file? (you only need the dll to run the component - the rest are source code files)

  24. 24 Mar 2003 at 09:30

    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

  25. 25 Feb 2003 at 02:01

    It's poor solution.


    When I upload over 300MB to test, This use over 1200MB memory!


    And I cannot stop uploading.


    kek..

  26. 23 Feb 2003 at 15:15

    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.

  27. 23 Feb 2003 at 15:02

    I think it is not quite /2.  Close but there is more going on then that.

  28. 14 Feb 2003 at 03:44

    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


  29. 06 Feb 2003 at 20:35

     Error Type:
    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


  30. 29 Jan 2003 at 00:48

    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

  31. 15 Jan 2003 at 15:17

    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!

  32. 07 Jan 2003 at 09:29

    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.


  33. 20 Dec 2002 at 14:39

    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!

  34. 05 Dec 2002 at 20:55

    for once code that works first time

  35. 01 Dec 2002 at 07:01

    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

  36. 26 Nov 2002 at 04:56

    Ya code, and toturial are BEST. BAGUS in Malaysia Language... I've learnt from you...

  37. 21 Nov 2002 at 17:45

    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 . . .

  38. 14 Nov 2002 at 10:54

    Yes. the FileSystemObject has a DeleteFile("c:\thepath\thefile.txt") method.

  39. 14 Nov 2002 at 10:46

    Is there any delete property to delete an existing file ?

  40. 17 Oct 2002 at 13:12

    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!

  41. 05 Sep 2002 at 10:27

    my webserver is winme + pws4.0

  42. 05 Sep 2002 at 10:22

    I think I have successfully registered the dll file. It seems working well but .....
    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!!!

  43. 27 Aug 2002 at 10:47

    or have ASP installed ...

  44. 19 Jul 2002 at 08:42

    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

  45. 18 Jul 2002 at 10:30

    Don't waste ya bandwidth.


    Okay so I need to download the .NET SDK and use tblimp.exe to create the type library from the binaries provided.


    DUH!

  46. 18 Jul 2002 at 08:27

    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  

  47. 17 Jul 2002 at 08:28

    basically, it hasn't regconised the ProgID you've used. This is most likely because you have not registered the DLL using regsvr32.exe

  48. 17 Jul 2002 at 05:21

    you must change a name of dll in asp page
    where you instance component
    Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")
    bye

  49. 11 Jul 2002 at 10:18

    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

  50. 10 Jul 2002 at 13:49

    instr for win2k
    start -> programs -> admin tools -> com services


    iis utilities


    components


    right click -> new

  51. 07 Jun 2002 at 11:34

    I think you'd just have to delete the existing file first....

  52. 28 May 2002 at 06:20

    Hi,


    Is there a way of overwriting an existing file if it has the same name???

  53. 05 May 2002 at 00:42

    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.


  54. 04 May 2002 at 23:47

    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?

  55. 04 May 2002 at 23:24

    Code:
    FileSize = GetVal("FileLen")/2


    Is this required because Unicode carries two bytes or something?  Thus, doubling up the file size?

  56. 04 May 2002 at 23:19

    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?

  57. 25 Apr 2002 at 23:17

    Thanks for the suggestion Aaron - I tried that initally and still no go. Guess its back to ftp

  58. 06 Apr 2002 at 05:00

    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

  59. 05 Apr 2002 at 10:34

    simple answer: no. the ASP script can't get hold of a file on the client's machine that way.....

  60. 05 Apr 2002 at 08:40

    Hi


    Is it posible to use :


    <input type="text" name="thefile">


    instead of


    <input type="file" name="thefile">


    in your asp page.


    thanks

  61. 03 Apr 2002 at 15:31

    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

  62. 27 Mar 2002 at 11:39

    DescriptionProgress Bar script:



    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>


  63. 26 Mar 2002 at 04:39

    Hi,
    How can add a progress bar in your file upload component.


    Amit

  64. 19 Mar 2002 at 19:52

    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?

  65. 16 Mar 2002 at 10:37

    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

  66. 11 Mar 2002 at 19:32

    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

  67. 11 Mar 2002 at 08:16

    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

  68. 27 Feb 2002 at 11:18

    yeah, it's just the sample page, then. I didn't check the tutorial, though...

  69. 27 Feb 2002 at 09:57

    hmmm.... is it just the source code that has that incorrect line? The tutorial has

    Code:
    Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")

  70. 27 Feb 2002 at 09:55

    Thanks for that. I shall update the tutorial

  71. 27 Feb 2002 at 06:25

    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


    Code:
    FileSize = GetVal("FileLen")


    to


    Code:
    FileSize = GetVal("FileLen")/2


    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


    Code:
    Set objUpload = Server.CreateObject("UploadIt.cUpload")


    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


    Code:
    Set objUpload = Server.CreateObject("ASPUploadComponent.cUpload")


    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

  72. 12 Feb 2002 at 11:32

    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

  73. 01 Feb 2002 at 01:59

    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

  74. 21 Dec 2001 at 14:04

    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.

  75. 20 Dec 2001 at 14:07

    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.

  76. 20 Dec 2001 at 13:15

    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

  77. 28 Nov 2001 at 13:39

    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.

  78. 20 Nov 2001 at 16:33

    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...

  79. 19 Nov 2001 at 15:42

    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.

  80. 06 Nov 2001 at 15:40

    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!

  81. 06 Nov 2001 at 15:17

    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?

  82. 24 Oct 2001 at 02:52

    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?

  83. 23 Oct 2001 at 10:24

    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

  84. 23 Oct 2001 at 05:31

    <%=strMsg%>
    not
    <%strMsg%>
    George Hester

  85. 23 Oct 2001 at 05:26

    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

  86. 23 Oct 2001 at 05:11

    Thank you man.  sorry for he trouble.  It works Marvelous.

  87. 23 Oct 2001 at 04:52

    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

  88. 23 Oct 2001 at 04:47

    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.

  89. 23 Oct 2001 at 04:26

    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?

  90. 19 Oct 2001 at 16:04

    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.

  91. 19 Oct 2001 at 14:15

    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.

  92. 19 Oct 2001 at 14:14

    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

  93. 19 Oct 2001 at 06:22

    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

  94. 19 Oct 2001 at 02:23

    should i register the dll?

  95. 18 Oct 2001 at 19:40

    cFormItem is the class module listed here

  96. 18 Oct 2001 at 15:21

    How is the cFormItem datatype defined???

  97. 01 Jan 1999 at 00:00

    This thread is for discussions of Uploading Files with ASP.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

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...