NET 上传 有进度条
2014-01-16 17:05
232 查看
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在压缩并上传文件';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
Thread.Sleep(1000);
Response.Write("<script>HideWait()</script>");
其中,最后一句Response.Write("<script>HideWait()</script>");为结束进度条的操作,即隐藏。使用时可将进程添加在此句代码之上,当进程执行完以后便结束进度条。
单击上传文件夹按钮时,开始出现进度条,当文件夹压缩并且上传成功后,进度条结束。
在TextBox中手动输入将要上传的文件夹路径及文件夹名称,单击“上传文件夹”按钮,代码如下:
/// <summary>
/// 上传文件夹
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "") //如果输入为空,则弹出提示
{
this.Response.Write("<script>alert('输入为空,请重新输入!')</script>");
}
else
{
//压缩文件夹
string zipPath = TextBox1.Text.Trim(); //获取将要压缩的路径(包括文件夹名)
string zipedPath = @"c:\temp"; //压缩文件夹的路径(包括压缩文件名)
Zip Zc = new Zip();
//加载进度条
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在压缩并上传文件';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
4000
Response.Flush();
Thread.Sleep(1000);
//压缩文件夹并上传
//调用Zip类中的ZipDir方法,压缩文件夹并上传,
//zipPath为原文件夹路径及文件夹名,zipedPath为压缩后上传的压缩文件路径及文件夹名,6为压缩等级
//具体参见上一篇博客或访问http://www.cnblogs.com/zhzhx/archive/2013/04/14/3021077.html
Zc.ZipDir(zipPath, zipedPath, 6);
//结束进度条
Response.Write("<script>HideWait()</script>");
//显示压缩文件夹信息
this.Label1.Text = "<Br/>";
this.Label1.Text += "文件压缩并且上传成功!";
this.Label1.Text += "<Br/>";
this.Label1.Text += "<li>" + "原文件路径:" + zipPath;
this.Label1.Text += "<Br/>";
this.Label1.Text += "<li>" + "压缩上传后文件路径:" + zipedPath;
}
}
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在压缩并上传文件';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
Thread.Sleep(1000);
Response.Write("<script>HideWait()</script>");
其中,最后一句Response.Write("<script>HideWait()</script>");为结束进度条的操作,即隐藏。使用时可将进程添加在此句代码之上,当进程执行完以后便结束进度条。
单击上传文件夹按钮时,开始出现进度条,当文件夹压缩并且上传成功后,进度条结束。
在TextBox中手动输入将要上传的文件夹路径及文件夹名称,单击“上传文件夹”按钮,代码如下:
/// <summary>
/// 上传文件夹
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "") //如果输入为空,则弹出提示
{
this.Response.Write("<script>alert('输入为空,请重新输入!')</script>");
}
else
{
//压缩文件夹
string zipPath = TextBox1.Text.Trim(); //获取将要压缩的路径(包括文件夹名)
string zipedPath = @"c:\temp"; //压缩文件夹的路径(包括压缩文件名)
Zip Zc = new Zip();
//加载进度条
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在压缩并上传文件';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
4000
Response.Flush();
Thread.Sleep(1000);
//压缩文件夹并上传
//调用Zip类中的ZipDir方法,压缩文件夹并上传,
//zipPath为原文件夹路径及文件夹名,zipedPath为压缩后上传的压缩文件路径及文件夹名,6为压缩等级
//具体参见上一篇博客或访问http://www.cnblogs.com/zhzhx/archive/2013/04/14/3021077.html
Zc.ZipDir(zipPath, zipedPath, 6);
//结束进度条
Response.Write("<script>HideWait()</script>");
//显示压缩文件夹信息
this.Label1.Text = "<Br/>";
this.Label1.Text += "文件压缩并且上传成功!";
this.Label1.Text += "<Br/>";
this.Label1.Text += "<li>" + "原文件路径:" + zipPath;
this.Label1.Text += "<Br/>";
this.Label1.Text += "<li>" + "压缩上传后文件路径:" + zipedPath;
}
}
相关文章推荐
- maven 之pom.xml
- HTML和CSS中如何判断ie各版本浏览器
- KVM的简单使用1
- cocos2dx连连看
- 如何运行Python程序
- 判断view是否显示
- (2)Hive安装与配置——深入浅出学Hive
- (1)初始Hive —— 深入浅出学Hive
- 根据网卡(eth0, eth1)获得对应的IP地址
- 入门dos,哈哈,发一个定时关机
- CSS3 Box-sizing
- 域控制引发文件服务器无法访问
- getContentLength()为-1 解决方法
- 网站建设之选择合适的主机
- NET获取计算机相关信息
- java乱码问题
- 设置本地子域名
- asp.net返回值当文件下载问题
- 各种传递参数和返回(ajax等)
- HTML5的桌面通知