First time implementing telerik RadUpload control

Ramesh picture Ramesh · Jan 10, 2012 · Viewed 8.1k times · Source

I am implementing telerik RadUpload in my asp.net web application.I added corresponding the handler and module entries in web.config.

<add path="Telerik.RadUploadProgressHandler.ashx"
   type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" validate="false" />
<add name="RadUploadModule"
   type="Telerik.Web.UI.RadUploadHttpModule" />

I have a functionality where I need to upload excel file and need to see the progress bar while uploading until it completes 100%.

PROBLEM: I am wondering how to capture the percentage of file uploaded and show it in progressarea.

MY CODE (Button_Click):

    Const total As Integer = 100

        Dim progress As RadProgressContext = RadProgressContext.Current
        progress.Speed = "N/A"
        Dim files As UploadedFileCollection = RadUpload1.UploadedFiles
        Dim up As RadUpload = RadUpload1
        If files IsNot Nothing AndAlso 0 <> files.Count Then
            For i As Integer = 0 To total - 1
             progress("SecondaryTotal") = total.ToString()
                progress("SecondaryValue") = i.ToString()
                progress("SecondaryPercent") = i.ToString()
                progress("CurrentOperationText") = files(0).GetName() & " is being processed..."

            If Not Response.IsClientConnected Then
                      Exit For
            End If
            progress.TimeEstimated = (total - i) * 100

            ---------ACTUAL UPLOAD FUNCTIONALITY HERE----------
             objUpload.CreateBulkUploadRequest(bytes)

           Next
        End If

Private Sub CreateBulkUploadRequest(bytes)

     StoreDocumentinImageServer(bytes)

End Sub

 Public Function StoreDocumentinImageServer(ByVal PostData As Byte()) As Integer

        Try

            Dim req As HttpWebRequest
            Dim resp As HttpWebResponse
            Dim postStream As Stream
            Dim respStream As StreamReader
            Dim Url As String
            Dim response As String = String.Empty
            Dim ImageId As Integer = 0
            Dim qryString As New StringBuilder("?fileSize=")
            qryString.Append(PostData.Length)
            qryString.Append("&userId=" + RequestedBy.ToString)
            qryString.Append("&applicationName=" + RequestType.ToString)
            qryString.Append("&imageName=" + FileName)
            qryString.Append("&mode=Insert")
            Url = ImageServiceUrl + qryString.ToString
            req = CType(WebRequest.Create(Url), HttpWebRequest)
            req.Method = "POST"
            req.ContentType = contenttype
            req.KeepAlive = True
            req.ContentLength = PostData.Length
            postStream = req.GetRequestStream()
            postStream.Write(PostData, 0, PostData.Length)
            resp = CType(req.GetResponse(), HttpWebResponse)
            respStream = New StreamReader(resp.GetResponseStream(), Encoding.Default)
            response = respStream.ReadToEnd()
            respStream.Close()
            resp.Close()

        Catch ex As Exception
            Throw ex
        End Try
    End Function

PROBLEM---- Now CreateBulkUploadRequest() method is Synchronous , it will take 10 min to upload and finally come out of the method execution. Now mean while how would I update the progress area and percentage of file upload status.

My biggest problem is CreateBulkUploadRequest() is in the loop of progress bar update code. so it calls as many times it is trying to update the progress area.

AM I DOING CORRECT ????????

Please Let me know If my question is not clear.

Looking forward for any suggestions.

Answer

M4N picture M4N · Jan 10, 2012

You don't have to handle the display of progress information yourself, it should be done automatically. Have a look at this sample code.