1

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.

carlbergenhem
  • 1,989
  • 13
  • 12
Ramesh
  • 103
  • 1
  • 10

2 Answers2

0

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

M4N
  • 94,805
  • 45
  • 217
  • 260
  • Sorry M4N , I tried the way you said, It is showing the progress area box, but not updating the prgogress bar with % uploaded, Is that anything I need to do ?????? – Ramesh Jan 11 '12 at 10:34
0

If you are just using the RadUpload and progress area to check the uploaded % then you do not need any additional code in the code-behind. The code (markup) mentioned in this demo should suffice.

However, If you want some custom progress monitoring, which it seems that you are doing with the code provided, you will need to go about this slightly differently. This demo covers just how custom progress monitoring should be implemented. I would double check that the code that you have implemented aligns with the sample in that demo.

carlbergenhem
  • 1,989
  • 13
  • 12
  • Thank you Carl for showing interest towards my problem, Actually my upload functionality is in CreateBulkUploadRequest() method which is taking time 10 min to execute. And also I kept that in for loop for updating progress bar,so method is getting executed many times. I am not clear to how to update progressbar with out looping and also without knowing the execution time of that method.... Please let me understand, I have seen the demo that you gave the link ,I followed the same example and wrote the above code, there they are using thread,but how can i implement the thread in this scenario. – Ramesh Jan 12 '12 at 04:23
  • How we will know the % of bytes that are getting uploaded, I am using http post to upload the file to other server. and while that process is happening in CreateBulkUploadRequest(bytes) method , i have to get the percentage of bytes completed and update the progress bar. somehthing like from one example .....................progress["SecondaryTotal"] = nBytesTotalL.ToString(); progress["SecondaryValue"] = nPercentCompleteL.ToString(); progress["SecondaryPercent"] = Convert.ToInt16(nPercentCompleteL).ToString(); – Ramesh Jan 12 '12 at 09:11
  • SECOND OPTION -- Atleast my progress bar should end excatly when the method completes the execution, It is ok if it doesnt give me % of completion. – Ramesh Jan 12 '12 at 10:15
  • For any of your options, you have to update the current Value and Percent fields in order to display any progress. From the look of things right now you are not providing additional updates to these fields during your upload. One option that you could use is to work with the InputStream directly, and either update these fields after every file has been successfully saved to wherever you are saving them. See this article for more information: http://www.telerik.com/help/aspnet-ajax/upload-manipulating-files.html – carlbergenhem Jan 12 '12 at 15:36