Re: FileUploaded event fired two times for each file uploded!

  •  03-13-2009, 11:29 AM

    Re: FileUploaded event fired two times for each file uploded!

     
    That example works fine!
    However, the following is my code, could you please show me what I'm doing wrong?
     
     
     

     
    <form id="form1" runat="server">

     

    <div class="content">

    <asp:ScriptManager ID="Scriptmanager1" runat="server">

    </asp:ScriptManager>

     

    <div id="divUpload" runat="server" >

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>

    <table style="width: 100%">

    <tr>

    <td style="width: 100px">

    Upload to path:

    <asp:Label ID="lblUploadPath" runat="server" ></asp:Label>

    </td>

    <td style="width: 100px">

    </td>

    </tr>

    <tr>

    <td style="width: 100px">

    </td>

    <td style="width: 100px">

    </td>

    </tr>

    </table>

    <div id="queuediv" style="display: none;">

    <div id="queuedivtablecontainer">

    </div>

    <div style="font-size:larger;padding-left:100px;margin:4px;">

    <a href="#" onclick="cancelalltasks();return false;">Cancel all tasks.</a>

    </div>

    </div>

    <CuteWebUI:UploadAttachments runat="server" ShowFileIcons="true" ManualStartUpload="true" ID="Uploader1"

    InsertText="Browse Files" >

    <VALIDATEOPTION MaxSizeKB="102400" />

    </CuteWebUI:UploadAttachments >

     

    <br />

    <br />

    <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()" Text="Upload" OnClick="SubmitButton_Click" />

    <br />

    <br />

    <div>

     

    <asp:ListBox runat="server" ID="ListBoxEvents" width="100%"></asp:ListBox>

    </div>

    <br />

    <br />

     

    <script type="text/javascript">

     

    function submitbutton_click()

    {

    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');

    var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');

    if(!window.filesuploaded)

    {

    if(uploadobj.getqueuecount()>0)

    {

    uploadobj.startupload();

    }

    else

    {

    var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;

    if(uploadedcount>0)

    {

    return true;

    }

    alert("Please browse files for upload");

    }

    return false;

    }

    window.filesuploaded=false;

    return true;

    }

    function CuteWebUI_AjaxUploader_OnPostback()

    {

    window.filesuploaded=true;

    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');

    submitbutton.click();

    return false;

    }

    </script>

     

    </ContentTemplate>

    </asp:UpdatePanel>

    </div>

    </div>

     

     

     

     

     

    </form>

     

    ------------------------------------------------------------------

    ---------------------------------------------------------------------------

     

    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    'MyBase.OnInit(e)

     

    AddHandler Uploader1.FileUploaded, AddressOf Uploader_FileUploaded

    End Sub

     

    Protected Sub InsertMsg(ByVal msg As String)

    ListBoxEvents.Items.Insert(0, msg)

    ListBoxEvents.SelectedIndex = 0

    End Sub

     

     

     

    Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click

    InsertMsg("You have uploaded " & uploadcount & "/" & Uploader1.Items.Count & " files.")

    End Sub

     

     

    Protected Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs) Handles Uploader1.FileUploaded

    uploadcount += 1

    Dim boolUploadSucceeded = False

     

    Dim uploader As CuteWebUI.Uploader = DirectCast(sender, CuteWebUI.Uploader)

    InsertMsg("File uploaded! " & args.FileName & ", " & args.FileSize & " bytes.")

    Dim strPath As String = Path.Combine(Session("CurrentPath"), args.FileName)

    'Check first if the folder size is enough to copy

     

    Dim folderRootSize As Long = GetFolderSize(GetRootLocation(), True)

    If QutaSize() <> 0 Then

     

    Dim lngNewTotalsize As Long = folderRootSize + ((args.FileSize / 1024) / 1024)

    If lngNewTotalsize > QutaSize() Then

     

    InsertMsg("Cannot Upload File: " & args.FileName & ", " & args.FileSize & " bytes, you are exceeding your quota limit.")

    Else

     

    args.CopyTo(strPath)

    boolUploadSucceeded = True

     

    End If

     

    Else

     

    args.CopyTo(strPath)

    boolUploadSucceeded = True

     

    End If

     

    If boolUploadSucceeded Then

     

    strUploadedFiles += ", Name: " & args.FileName & " Uploaded to path: " & Session("CurrentPath") & " Size: " & args.FileSize

    End If

     

    'Copys the uploaded file to a new location.

     

    'You can also open the uploaded file's data stream.

     

    'System.IO.Stream data = args.OpenStream();

     

    End Sub

View Complete Thread