Rank: Newbie Groups: Member
Joined: 4/8/2014 Posts: 0
|
Hi a short question: How can I download the file using the progress bar?
Code: HTML/ASPX
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript" src="<%=this.ResolveUrl("~/Scripts/jquery-1.9.1.min.js") %>"></script>
<script type="text/javascript">
$(document).ready(function () {
var pb = eo_GetObject('<%=ProgressBar1.ClientID %>');
if (null != pb) {
pb.startTask();
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<eo:ProgressBar ID="ProgressBar1" runat="server" BorderColor="Black" BorderWidth="1px"
Height="16px" IndicatorColor="LightBlue" Value="0" ControlSkinID="None" BorderStyle="Solid"
Width="300px" ShowPercentage="true" StartTaskButton="btnStart" StopTaskButton="btnStop" OnRunTask="ProgressBar1_RunTask">
</eo:ProgressBar>
<br/>
<asp:LinkButton id="btnStart" runat="server">Start</asp:LinkButton>
<asp:LinkButton id="btnStop" runat="server">Stop</asp:LinkButton>
<eo:Downloader runat="server" ID="Downloader1" DownloadButtonID="Button1" DirectLinkLabelID="Label1" DynamicContent="True" OnDownload="Downloader1_Download"></eo:Downloader>
<asp:Label runat="server" ID="Label1"></asp:Label>
<asp:Button Runat="server" ID="Button1" Text="Generate File & Download"></asp:Button>
</div>
</form>
</body>
</html>
Code: C#
public static MemoryStream aa = new MemoryStream();
protected void ProgressBar1_RunTask(object sender, EO.Web.ProgressTaskEventArgs e)
{
e.UpdateProgress(0);
aa = Report(e);//Execute other function
Downloader1_Download(object sender, EO.Web.DownloadEventArgs e);//How can i call download event?
e.UpdateProgress(100);
}
protected class ContentGenerator : EO.Web.DynamicDownloadContent
{
protected override void GenerateContent()
{
SetFileName("test.PDF", -1);
byte[] buffer = aa.GetBuffer();
Write(buffer, 0, buffer.Length);
}
}
protected void Downloader1_Download(object sender, EO.Web.DownloadEventArgs e)
{
NameValueCollection args = new NameValueCollection();
e.DynamicDownload(typeof(ContentGenerator), args);
}
protected MemoryStream Report(EO.Web.DownloadEventArgs e)
{
MemoryStream ms = new MemoryStream();
for (int i = 0; i < 100; i++)
{
if (e.IsStopped)
break;
other();//Execute other function
e.UpdateProgress(i);
}
return ms;
}
Thanks for your help ^^.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, You can take a look of this sample: http://demo.essentialobjects.com/Demos/Progress%20Bar/Server%20Side%20Task%20-%20Advanced%202/Demo.aspxThis sample demonstrates how to trigger another task after your ProgressBar is done. In the sample, the code calls setTimeout to call eo_Callback. In your case, you would want to call setTimeout to call Downloader.Start function: http://www.essentialobjects.com/doc/1/jsdoc.public.downloader.start.aspxHope this helps. Please feel free to let us know if you have any more questions. Thanks!
|