This is a migrated thread and some comments may be shown as answers.

Start radprogress after file uploaded

1 Answer 51 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 27 Nov 2012, 12:44 PM
Hi,
i've this code aspx and vbnet 2010:

how can I start the progressbar simultaneously upload the file? calculate the actual file transfer?
<form id="form1" runat="server"
    style="font-family: Verdana; font-size: small; background-image: url('Image/Upload.jpg'); background-repeat: no-repeat; width: 640px; height: 480px">
    <div>
         <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
        </telerik:RadScriptManager>
                     <br />
        <table style="border: 0px; margin: 0px; padding: 0px; width: 100%">
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                 </td>  
            </tr>
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                     </td>
            </tr>
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                     </td>
            </tr>
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                    <telerik:RadUpload ID="RadUpload1" Runat="server"
                        AllowedFileExtensions="jpg,jpeg,png,gif" OverwriteExistingFiles="True"
                        TargetFolder="public/image_profile" ControlObjectsVisibility="None"
                        InputSize="50" Height="22px" style="text-align: left" Skin="Sunset">
                        <Localization Select="Cerca" />
                    </telerik:RadUpload>
                        <asp:CustomValidator ID="CustomValidator1" runat="server"
                        ErrorMessage="File errato" ClientValidationFunction="validateRadUpload" OnServerValidate="CustomValidator1_ServerValidate" ForeColor="Red"></asp:CustomValidator>
                    <div style="font-size:x-small">Il file deve avere le seguenti estensioni: .jpg, .jpeg, .png
                    </div>
                    <div>
                    </div>
                    <telerik:RadButton ID="RadButton1" runat="server"
                        Text="Avvia trasferimento" Skin="Sunset">
                    </telerik:RadButton>
            <script type="text/javascript">
                function validateRadUpload(source, e) {
                    e.IsValid = false;
                    var upload = $find("<%= RadUpload1.ClientID %>");
                    var inputs = upload.getFileInputs();
                    for (var i = 0; i < inputs.length; i++) {
                        //check for empty string or invalid extension    
                        if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
                            e.IsValid = true;
                            break;
                        }
                    }
                }
            </script>
                </td>
            </tr>
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                <div>
                </div>
                    <asp:Label ID="Label1" runat="server" Text="Nessun file caricato"
                        ForeColor="Green"></asp:Label>
                    <asp:Repeater ID="Repeater1" runat="server" Visible="False">
                                        <HeaderTemplate>
                                        <div style="color: green">
                                        File caricato:</div>
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <%#DataBinder.Eval(Container.DataItem, "FileName")%>
                                            <%#DataBinder.Eval(Container.DataItem, "ContentLength").ToString() + " bytes"%>
                                            <br />
                                        </ItemTemplate>
                    </asp:Repeater>
                </td>
            </tr>
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                    <telerik:RadProgressManager ID="RadProgressManager1" runat="server" />
                    <telerik:RadProgressArea ID="RadProgressArea1" Runat="server"  ProgressIndicators="FilesCountBar, FilesCount, FilesCountPercent, SelectedFilesCount, CurrentFileName">
                            <Localization Uploaded="Trasferito" CurrentFileName="Trasferimento file:"
                            EstimatedTime="Tempo stimato:" Total="Totale " TotalFiles="Totale files: "
                            TransferSpeed="Velocità: " UploadedFiles="File trasferiti:"></Localization>
                    </telerik:RadProgressArea>
                </td>
            </tr>
            <tr>
                <td style="border-style: none; border-color: inherit; border-width: 0px; margin: 0px; padding: 0px; text-align: center;">
                <div>
                </div>
                    <asp:ImageButton ID="Imgbtnesci" runat="server"
                        ImageUrl="~/Image/esci1.png" ValidationGroup="esci" />
                </td>
            </tr>
        </table>
    </div>
    </form>
Protected Sub RadButton1_Click(sender As Object, e As System.EventArgs) Handles RadButton1.Click
        If RadUpload1.UploadedFiles.Count > 0 Then
            UpdateProgressContext()
            Repeater1.DataSource = RadUpload1.UploadedFiles
            Repeater1.DataBind()
            Label1.Visible = False
            Repeater1.Visible = True
        Else
            Label1.Visible = True
            Repeater1.Visible = False
        End If
    End Sub
    Private Sub UpdateProgressContext()
        Const total As Integer = 100
 
        Dim progress As RadProgressContext = RadProgressContext.Current
        progress.Speed = "N/A"
 
        For i As Integer = 0 To total - 1
            progress.PrimaryTotal = 1
            progress.PrimaryValue = 1
            progress.PrimaryPercent = 100
 
            progress.SecondaryTotal = total
            progress.SecondaryValue = i
            progress.SecondaryPercent = i
 
            progress.CurrentOperationText = "Step " & i.ToString()
 
            If Not Response.IsClientConnected Then
                Exit For
            End If
            progress.TimeEstimated = (total - i) * 100
            System.Threading.Thread.Sleep(100)
        Next
    End Sub
 
    Protected Sub CustomValidator1_ServerValidate(source As Object, e As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
        e.IsValid = (RadUpload1.InvalidFiles.Count = 0)
    End Sub


1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 30 Nov 2012, 09:23 AM
Hello Fabio,

Please take a look at the following help articles and demo of both RadAsyncUpload control and RadUpload control. I believe that they would be very helpful for accomplishing the scenario that you need to achieve:

Kind regards,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Upload (Obsolete)
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or