我正在我的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我做得正确?????????
请告诉我如果我的问题不明确。
期待任何建议。