Re: Implementation

  •  07-07-2011, 2:13 PM

    Re: Implementation

    Hi SteveS,
     
    You can run the following two examples on your asp uploader installation directly:
     
    example1:

    <%@ 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 - Start uploading manually
     </title>
    </head>
    <body>
     <div class="demo">
       <!-- 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.ManualStartUpload=true    
        %>
        <%=uploader.GetString() %>   
        <br />
        
       <table id='clientTable' style="display: none; font-size: 9pt; border-collapse: collapse"
        border="1" cellspacing="0" cellpadding="5">
        <tr>
         <td>
          FileName
         </td>
         <td>
          Description
         </td>
         <td>
          Status
         </td>
        </tr>
       </table>  
        <br />
        <button id='btnUpload' style="display: none;" onclick="Upload_Click();return false;">Start Upload</button> 
       </form>
     </div>
    <script type="text/javascript">
        var btnUpload = document.getElementById("btnUpload");
        var clientTable = document.getElementById("clientTable");
        var uploader = document.getElementById('myuploader');
        //var buttonTell = document.getElementById('buttonTell');
        var buttonTellClicked = false;

        function Upload_Click() {   
            var uploadobj = document.getElementById('myuploader');
      if (uploadobj.getqueuecount() > 0)
      {
          for(var i=1;i<clientTable.rows.length;i++)
          {
            var fieldValue= clientTable.rows.item(i).cells[1].children[0].value;       
            if(fieldValue==null||fieldValue.length<1)
            {
                alert("Please fill in values!");
                return;
            }      
       }
       uploadobj.startupload();
      }
      else
      {
       alert("Please browse files for upload");
      }
        }
        function buttonTell_Click() {
            buttonTellClicked = true;
            var items = uploader.getitems();
            for (var i = 0; i < items.length; i++) {
                switch (items[i].Status) {
                    case "Queue":
                    case "Upload":
                        uploader.startupload();
                        return false;
                }
            }
            return true;
        }
        function CuteWebUI_AjaxUploader_OnPostback() {
            if (buttonTellClicked) {
                buttonTell.click();
                return false;
            }
        }
        function CuteWebUI_AjaxUploader_OnQueueUI(files) {
            btnUpload.style.display = files.length > 0 ? "" : "none";
            clientTable.style.display = files.length > 0 ? "" : "none";
            ShowMyClientTable(files);
            return false;
        }

        function ShowMyClientTable(files) {
            var map = {}
            var newlist = [];
            for (var i = 1; i < clientTable.rows.length; i++) {
                var row = clientTable.rows.item(i);
                row._scan = false;
                map[row._filekey] = row;
            }
            //update existing row
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                var row = map[file.InitGuid || file.FileName];
                if (row == null) {
                    newlist.push(file);
                    continue;
                }
                row._scan = true;
                UpdateToRow(row, file);
            }
            //delete removed row
            for (var i = 1; i < clientTable.rows.length; i++) {
                var row = clientTable.rows.item(i);
                if (!row._scan) {
                    clientTable.deleteRow(i);
                    i--;
                }
            }
            //add new row:
            for (var i = 0; i < newlist.length; i++) {
                var file = newlist[i];
                var row = clientTable.insertRow(-1);
                row.insertCell(-1);
                row.insertCell(-1);
                row.insertCell(-1);
                UpdateToRow(row, file);
            }
        }
        function UpdateToRow(row, file) {

            row._file = file;
            row._filekey = file.InitGuid || file.FileName;
            if (!row._textbox) {
                row._textbox = document.createElement("INPUT");
                row._textbox.type = "text";
                row.cells.item(1).appendChild(row._textbox);
            }
            row._textbox.onchange = function() {
                file.SetClientData(row._textbox.value);
            }
            row.cells.item(0).innerHTML = file.FileName;
            switch (file.Status) {
                case "Queue":
                    row.cells.item(2).innerHTML = "<a href='#' onclick='CancelQueueItem(this);return false'>remove</a>";
                    break;
                case "Finish": //uploaded
                case "Upload": //uploading
                case "Error": //cancelled
                default:
                    row.cells.item(2).innerHTML = file.Status;
                    break;
            }
        }
        function CancelQueueItem(link) {
            var td = link.parentNode;
            var row = td.parentNode;
            var file = row._file;
            file.Cancel();
        }
        //prevent duplicated items:
        function CuteWebUI_AjaxUploader_OnSelect(files) {
            var sames = [];
            var items = uploader.getitems();
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                var exists = false;
                for (var j = 0; j < items.length; j++) {
                    var item = items[j];
                    if (item.FileName == file.FileName) {
                        exists = true;
                    }
                }
                if (exists) {
                    sames.push(file.FileName);
                    file.Cancel();
                }
            }
            if (sames.length > 0) {
                alert("These file(s) are already in the queue : \r\n\t" + sames.join('\r\n\t'));
            }
        }
    </script>
    </body>
    </html>

     
    example2:

    <%@ 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();
     }
     function CuteWebUI_AjaxUploader_OnQueueUI(files) {     
            //return false;
        }   
        function CuteWebUI_AjaxUploader_OnSelect(files) {
          var form1= document.forms[0];    
          if(form1.fname.value==""){ 
             window.alert("please input first name!"); 
             form1.fname.focus() 
             return false; 
          }
          if(form1.lname.value==""){ 
             window.alert("please input first name!"); 
             form1.lname.focus() 
             return false; 
          }
        }   
     </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">
       First Name: <input type="text" name="fname" />
                <br />
                Last Name: <input type="text" name="lname" />
                <br />
       <%
       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")
     Next
    End If
    %>   
     </div>
    </body>
    </html>

    Thanks for asking
View Complete Thread