Changing filename using AJAX uploader

Last post 03-11-2011, 10:58 AM by Eric. 1 replies.
Sort Posts: Previous Next
  •  03-10-2011, 10:37 PM 66624

    Changing filename using AJAX uploader

    I am using the following code in my ajax handler:
     
    <%@ Language="VBScript" %>
    <!-- #include file="aspuploader/include_aspuploader.asp" -->
    <%

    Dim uploader,mvcfile
    Set uploader=new AspUploader
    Set mvcfile=uploader.GetValidatingFile()    
            
        targetfilepath= "savefiles/myprefix_" & mvcfile.FileName    
            
        dim fs    
        Set fs=Server.CreateObject("Scripting.FileSystemObject")    
        if fs.FileExists(server.mappath(targetfilepath)) then    
          fs.DeleteFile(server.mappath(targetfilepath))    
        end if    
        set fs=nothing    
            
        mvcfile.MoveTo( server.mappath(targetfilepath))    
       
        uploader.WriteValidationOK()

    If Request.Form("guidlist")&""<>"" Then
        Dim list,i
        list=Split(Request.Form("guidlist"),"/")
        Response.Write("[")
        For i=0 to Ubound(list)
            if i>0 then
                Response.Write(",")
            end if
            Set mvcfile=uploader.GetUploadedFile(list(i))
            Response.Write("{")
            Response.Write("FileGuid:'" & mvcfile.FileGuid & "'")
            Response.Write(",")
            Response.Write("FileSize:'" & mvcfile.FileSize & "'")
            Response.Write(",")
            Response.Write("FileName:'" & mvcfile.FileName & "'")
            Response.Write("}")
        Next
        Response.Write("]")
    End If


    Response.End()

    %>


    However I am getting the following error:

    Microsoft JScript runtime error '800a139e'

    Call PreProcessRequest before access this member! at function Ox29

    /aspuploader/resources/coreimpl.js, line 1


    Any suggestions?
















     
     
     
     
     
  •  03-11-2011, 10:58 AM 66630 in reply to 66624

    Re: Changing filename using AJAX uploader

    Dear cunninw,
     
    Please refer to the following snippet:

    --
    <%@ Language="VBScript" %>
    <!-- #include file="aspuploader/include_aspuploader.asp" -->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title>
      Form - Multiple files upload
     </title>
     <link href="demo.css" rel="stylesheet" type="text/css" />
     
     <script type="text/javascript">
     function CuteWebUI_AjaxUploader_OnPostback() {
      //submit the form after the file have been uploaded:
      document.forms[0].submit();
     }
     </script>
    </head>
    <body>
     <div class="demo">                       
            <h2>Selecting multiple files for upload</h2>
      <p>ASP Uploader allows you to select multiple files and upload multiple files at once.</p>
      
       <!-- do not need enctype="multipart/form-data" -->
       <form id="form1" method="POST">
       <%
       Dim uploader
       Set uploader=new AspUploader
       uploader.MaxSizeKB=10240
       uploader.Name="myuploader"
       uploader.InsertText="Upload File (Max 10M)"
       uploader.MultipleFilesUpload=true
       %>
       <%=uploader.GetString() %>
       </form>
       
       <br/><br/>
    <%
    If Request.Form("myuploader")&""<>"" Then
     Dim list,i
     
     'Gets the GUID List of the files based on uploader name
     list=Split(Request.Form("myuploader"),"/")
     For i=0 to Ubound(list)
      if i>0 then
       Response.Write("<hr/>")
      end if
      Dim mvcfile
      
      'get the uploaded file based on GUID
      Set mvcfile=uploader.GetUploadedFile(list(i))
      Response.Write("<div style='font-family:Fixedsys'>")
      Response.Write("Uploaded File:")
       'Gets the name of the file.
      Response.Write("<br/>FileName: ")
      Response.Write(mvcfile.FileName)
      'Gets the size of the file.
      Response.Write("<br/>FileSize: ")
      Response.Write(mvcfile.FileSize)
      'Gets the temp file path.
      Response.Write("<br/>FilePath: ")
      Response.Write(mvcfile.FilePath)
      Response.Write("</div>")
      'Copys the uploaded file to a new location.   
            'mvcfile.CopyTo("/uploads")           
            'Moves the uploaded file to a new location.   
            'mvcfile.MoveTo("/uploads")
             targetfilepath= "savefiles/myprefix_" & mvcfile.FileName       
             dim fs   
             Set fs=Server.CreateObject("Scripting.FileSystemObject")      
             if fs.FileExists(server.mappath(targetfilepath)) then   
                fs.DeleteFile(server.mappath(targetfilepath))   
             end if   
             set fs=nothing
             mvcfile.MoveTo( server.mappath(targetfilepath))
          Next
    End If
    %>   
     </div>
    </body>
    </html>
    Thank you for asking
View as RSS news feed in XML