Live Support, Chat, Upload Control and Rich Text Editor
Welcome to Support forums Sign in | Join | Help |Client Center
in Search

How do I code for single file manual upload?

Last post 02-15-2012, 11:36 AM by Kenneth. 8 replies.
Sort Posts: Previous Next
  •  02-10-2012, 4:31 PM 72987

    How do I code for single file manual upload?

    Greetings,
     
    I'm having trouble figuring out how to code the manual upload of a single file (MultipleFilesUpload = False).
     
    ------ASPx Page-------
     <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Select File" OnFileUploaded="Uploader_FileUploaded"  ManualStartUpload="True">
                </CuteWebUI:Uploader>
     
     <asp:Button ID="btnUpload" runat="server" Text="Upload" />
     
    ------Code Behind---------
     Protected Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)
            'Copys the uploaded file to a new location.
            args.CopyTo(Server.MapPath("~/uploads/") & args.FileName)
        End Sub
     
    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
     
             'What goes here?  Uploader1.Upload requires file size and file name which I don't know how to retrieve from the control.
     
    End Sub 
     
    ----------------------------
     
    When I set  MultipleFilesUpload = True, everything works well.  However, I'd like to validate other information on the form prior to uploading the file.  How do I retrieve the file size and file name from the control so that I may then call Uploader1.Upload(filesize, filename, temppath)?
     
    Thanks!
  •  02-12-2012, 9:53 PM 72995 in reply to 72987

    Re: How do I code for single file manual upload?

    Hi dmathews,
     
    The example below shows you how to get the file info after uploaded.
     
    <%@ Page Language="C#" %>
    <%@ Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <script runat="server">
      
        protected void b1_Click(object sender, EventArgs e)
        {
            label1.Text += uploader1.Items[0].FileName;
            label1.Text += "<br />";
            label1.Text += uploader1.Items[0].FileSize;
        }
    </script>
    <body>
        <form id="form1" runat="server">
            <div>
                <CuteWebUI:UploadAttachments ID="uploader1" runat="server" MultipleFilesUpload="false">
                </CuteWebUI:UploadAttachments>
                <asp:Button ID="b1" runat="server" Text="get file info" OnClick="b1_Click" /><br />
                <asp:Label ID="label1" runat="server"></asp:Label>
            </div>
        </form>
    </body>
    </html>
     
    Regards,
     
    Ken 
  •  02-14-2012, 9:33 AM 73024 in reply to 72995

    Re: How do I code for single file manual upload?

    Thanks Ken.
     
     I was incorrectly using <CuteWebUI:Uploader> instead of <CuteWebUI:UploadAttachments>.
  •  02-14-2012, 10:47 AM 73026 in reply to 72995

    Re: How do I code for single file manual upload?

    One more issue:
     
    I'm now getting the following error:
     
    "Index out of range Parameter name: index Actual value was 0." 
     
     I'm not sure what I'm missing.  My code is as follows:
     
    Imports CuteWebUI
     
    Partial Class me_Files
        Inherits System.Web.UI.Page
     
        Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
             dim filename, filesize as String
     
             filename = uploader1.Items(0).FileName
             filesize = uploader1.Items(0).FileSize
       End Sub
     End Class
     ----------ASPx Page---------------
    <%@ Page Title="" Language="VB" MasterPageFile="~/SSFMaster.master" AutoEventWireup="false" CodeFile="Files.aspx.vb" Inherits="me_Files" %>
     
     <CuteWebUI:UploadAttachments ID="uploader1" runat="server" MultipleFilesUpload="false">
                </CuteWebUI:UploadAttachments>
     
    <%@ Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI" %> 
     
     <%@ MasterType VirtualPath="~/SSFMaster.master" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="CHead" Runat="Server">
        <link rel="Stylesheet" href="../css/aStyles.css" type="text/css" media="screen" />
    </asp:Content>
     
    <asp:Content ID="Content2" ContentPlaceHolderID="CMain" Runat="Server">
        <div> 
              <CuteWebUI:UploadAttachments ID="uploader1" runat="server" MultipleFilesUpload="false">
                </CuteWebUI:UploadAttachments>
             <asp:Button ID="btnUpload" runat="server" Text="Upload" /> 
       </div>
    </asp:Content> 
  •  02-15-2012, 6:12 AM 73028 in reply to 73026

    Re: How do I code for single file manual upload?

    Hi dmathews,
     
    Before you get the item, please ensure that the uploader attachment has items there. 
     
    If uploader1.Items.Count <> 0 Then 
       Dim name As String = uploader1.Items(0).FileName
    End If 
     
    Regards,
     
    Ken 
  •  02-15-2012, 10:29 AM 73032 in reply to 73028

    Re: How do I code for single file manual upload?

    Hi Ken,
     
    I'm sorry I didn't clarify that.  The problem is that the uploader attachment never has any items.  When debugging, after I add an attachment, I click the Submit button and step through my code.  The items count is always 0.
     
    Any ideas as to what I'm doing wrong?
     
    Thanks!
  •  02-15-2012, 10:38 AM 73033 in reply to 73032

    Re: How do I code for single file manual upload?

    Hi dmathews,
     
    Can you try the example I sent above? Does it work for you? If yes, please refer to my code and find out what is the difference with yours.
     
    Regards,
     
    Ken 
  •  02-15-2012, 11:17 AM 73034 in reply to 73033

    Re: How do I code for single file manual upload?

    Ken,
     
    Yes, I was able to get your code to work but when I add 'ManualStartUpload="True"' to the control, I am then unable to get the filename/filesize because the items count is 0.
     
    But if I try to call uploader1.upload,  I'm required to supply filename, filesize, and temppath.
     
    So when doing a manual upload, how do I get the filename and filesize required to upload the file since these items aren't in the collection until after upload.
     
    I'm sorry if I'm missing something here.
     
     
  •  02-15-2012, 11:36 AM 73035 in reply to 73034

    Re: How do I code for single file manual upload?

    Hi dmathews,
     
    Try
     
    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">   
        protected void b1_Click(object sender, EventArgs e)
        {
            if (Uploader1.Items.Count != 0)
                label1.Text = Uploader1.Items[0].FileName;
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Start uploading manually</title>
    </head>
    <body>
        <form id="form1" runat="server">
         <asp:Label ID="label1" runat="server"></asp:Label><br />
            <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"
                InsertText="Browse Files (Max 1M)">
            </CuteWebUI:UploadAttachments>
            <br />
            <br />
            <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"
                Text="Submit" /><br />
            <p>
                after you click on the submit button</p>
            <asp:Button ID="b1" runat="server" Text="get info after click the submit button"
                OnClick="b1_Click" /><br />
            <p>
                after you selected the file, before click on the submit button</p>
            <input type="button" value="get info before click the submit button" onclick="showFile()" /><br />
           
            <script type="text/javascript">
    var fileList;
    function submitbutton_click()
    {
    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');
    var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');
    if(!window.filesuploaded)
    {
    if(uploadobj.getqueuecount()>0)
    {
    uploadobj.startupload();
    }
    return false;
    }
    window.filesuploaded=false;
    return true;
    }
    function CuteWebUI_AjaxUploader_OnPostback()
    {
    window.filesuploaded=true;
    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');
    submitbutton.click();
    return false;
    }
    function CuteWebUI_AjaxUploader_OnQueueUI(list)
        {
            fileList=list;
        }
        function showFile()
        {
            alert(fileList[0].FileName);
        }
            </script>
        </form>
    </body>
    </html>
     
    Regards,
     
    Ken 
View as RSS news feed in XML
Powered by ASP.Net
Copyright 2003 - 2017 CuteSoft Components Inc.. All rights reserved.