首次实施telerik RadUpload控件

时间:2012-01-10 15:20:15

标签: asp.net ajax telerik radupload

我正在我的asp.net web应用程序中实现telerik RadUpload。我在web.config中添加了相应的处理程序和模块条目。

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

我有一个功能,我需要上传excel文件,需要在上传时看到进度条,直到它完成100%。

问题:我想知道如何捕获上传文件的百分比并将其显示在进度区域中。

我的代码(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

问题----现在CreateBulkUploadRequest()方法是同步的,上传需要10分钟,最后退出方法执行。现在意味着我如何更新进度区域和文件上传状态的百分比。

我最大的问题是CreateBulkUploadRequest()处于进度条更新代码的循环中。 所以它会多次调用它来尝试更新进度区域。

AM我做得正确?????????

请告诉我如果我的问题不明确。

期待任何建议。

2 个答案:

答案 0 :(得分:0)

您不必自己处理进度信息的显示,应该自动完成。看看this sample code

答案 1 :(得分:0)

如果您只是使用RadUpload和进度区来检查上传的%,那么您在代码隐藏中不需要任何其他代码。 this demo中提到的代码(标记)就足够了。

但是,如果您想要一些自定义进度监控,而您似乎正在使用所提供的代码,则需要稍微改变一下。 This demo涵盖了应如何实施自定义进度监控。我会仔细检查你实现的代码是否与该演示中的示例一致。