.Net neatupload上传控件实现文件上传的进度条
1. 引入bin文件 (可以到neatupload官网下载,也可以到教育厅申报系统中找)

2. 将控件加入到工具栏,在工具栏中点鼠标右键,如图:

3. 加入neatuplaod这个文件夹(可以到neatupload官网下载,也可以到教育厅申报系统中找)



4. Webconfig的配置(3个地方)
<configSections>配置节下配置:
<!--配置NeatUpload sectionGroup配置节-->
<sectionGroup name="system.web">
<section name="neatUpload" type="Brettle.Web.NeatUpload.ConfigSectionHandler, Brettle.Web.NeatUpload" allowLocation="true" />
</sectionGroup>
<system.web>配置节下配置:
<!--配置NeatUpload neatUpload配置节-->
<neatUpload useHttpModule="True" maxNormalRequestLength="4096" maxRequestLength="2097151" defaultProvider="FilesystemUploadStorageProvider">
<providers>
<add name="FilesystemUploadStorageProvider"
type="Brettle.Web.NeatUpload.FilesystemUploadStorageProvider, Brettle.Web.NeatUpload" />
</providers>
</neatUpload>
<httpModules>配置节下配置:
<!--配置NeatUpload httpModules配置节-->
<!--如果不加这httpmodules,进度条不显示-->
<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload"/>
5. 页面代码
<%@ Register Assembly="Brettle.Web.NeatUpload" Namespace="Brettle.Web.NeatUpload"
TagPrefix="Upload" %>
<link href="../../../../NeatUpload/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
function ToggleVisibility(id, type) {
el = document.getElementById(id);
if (el.style) {
if (type == 'on') {
el.style.display = 'block';
}
else {
el.style.display = 'none';
}
}
else {
if (type == 'on') {
el.display = 'block';
}
else {
el.display = 'none';
}
}
}
</script>
<Upload:InputFile ID="AttachFile" runat="server" />
<asp:Button ID="btnAdd" runat="server" Text="上传" OnClientClick="ToggleVisibility('ProgressBar','on')"
OnClick="btnAdd_Click" />
<asp:Label ID="Label10" runat="server" Text="*最大上传为4M" ForeColor="Red"></asp:Label>
<div id="ProgressBar" style="display: none">
<Upload:ProgressBar ID="pbProgressBar" runat='server' Inline="true" Width="800px"
Height="50px" AllowTransparency="False">
</Upload:ProgressBar>
</div>
6. 页面后台代码范例:
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(AttachFile.FileName))
{
int ProjectID = this.CurrentProjectID;
string FileName = this.AttachFile.FileName;//获取上传文件的文件名
string FileNameExtenter =System.IO.Path.GetExtension(FileName).ToLower(); ;//获取扩展名
if (AttachFile.FileContent.Length > * && AttachFile != null)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), DateTime.Now.Ticks.ToString(), "<script>alert('文件大于4M,不能上传')</script>");
Stream Sr = AttachFile.FileContent;//创建数据流对象
Sr.Close();
// this.Response.Write("<script language=javascript>alert('文件大于4M,不能上传!');history.go(-1);</script>");
return;
}
if (AttachFile.FileContent.Length == )
{
this.Response.Write("<script language=javascript>alert('空文件,不能上传!');history.go(-1);</script>");
Stream Sr = AttachFile.FileContent;//创建数据流对象
Sr.Close();
return;
}
if (AttachFile != null && FileName != null)
{
if (FileNameExtenter == ".doc")
{
Stream Sr = AttachFile.FileContent;//创建数据流对象
int upLength = Convert.ToInt32(AttachFile.ContentLength);
byte[] b = new byte[upLength];//定义byte型数组
Sr.Read(b, , upLength); // 数据存放到b数组对象实例中,其中0代表数组指针的起始位置,uplength表示要读取流的长度(指针的结束位置)
Binary Content = new Binary(b);
Attachment _attachment = new Attachment();
_attachment.Entity = "ReportProject";
_attachment.EntityID = ProjectID;
_attachment.Content = Content;
_attachment.FileName = FileName;
_attachment.UsedFlag = ;
_attachment.Creator = this.CurrentProjectID.ToString();
_attachment.CreateTime = System.DateTime.Now;
_attachment.LastEditor = this.CurrentProjectID.ToString();
_attachment.LastEditTime = System.DateTime.Now;
DataContext.Attachment.InsertOnSubmit(_attachment);
DataContext.SubmitChanges();
this.gv.DataBind();
Sr.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), DateTime.Now.Ticks.ToString(), "<script>alert('附件上传成功!请检查!')</script>");
this.gv.DataBind();
//ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), DateTime.Now.Ticks.ToString(), "<script>window.alert('附件上传成功!');window.location.href=window.location.href;</script>", false);
//ProgressBar.Visible = false;
return;
}
else
{
this.Response.Write("<script language=javascript>alert('不能上传word以外 文件!请先将文件将转换为word(后缀名必须为doc)形式再上传');history.go(-1);</script>");
Stream Sr = AttachFile.FileContent;//创建数据流对象
Sr.Close();
return;
}
}
}
else
{
this.Response.Write("<script language=javascript>alert('请选择上传文件');history.go(-1);</script>");
return;
}
}
//若要上传到本地文件中
//代码:
string path = Server.MapPath("~") + "\\File\\UpLoads\\" + Path.GetFileName(NewUpFile.PostedFile.FileName);
NewUpFile.SaveAs(path);
7. 注意的地方
1>.当需要报错的时候,在报错的函数必须有
Stream Sr = AttachFile.FileContent;//创建数据流对象 Sr.Close();
看似多此一举,但是不写就会有错,
2> . 而且在进度条走完以后后台代码才会执行,故而如果文件过大,待文件上传完毕后提示文件过大会影响用户体验,这个问题待解决
.Net neatupload上传控件实现文件上传的进度条的更多相关文章
- 在EasyUI项目中使用FileBox控件实现文件上传处理
我在较早之前的随笔<基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用>Web框架介绍中介绍了基于Uploadify的文件上传操作,免费版本用的是J ...
- 利用bootsrap控件 实现文件上传功能
源代码实例:https://github.com/kartik-v/bootstrap-fileinput 一.jsp页面 <%@ page language="java" ...
- Js获取file上传控件的文件路径总结
总结一个获取file上传控件文件路径的方法 firefox由于保护机制只有文件名,不能获取完整路径. document.getElementById('file').onchange = functi ...
- jquery本地上传预览扩展(隐藏上传控件单击图片上传支持ie!!)
我用到的原材料地址:http://www.cnblogs.com/leejersey/p/3660202.html 修改后: /// <reference path="../../Js ...
- 037. asp.netWeb用户控件之五使用用户控件实现文件上传功能
fileUpload.ascx代码: <%@ Control Language="C#" AutoEventWireup="true" CodeFile= ...
- WebForm之FileUpload控件(文件上传)
FileUpload控件要与Button.LinkButton.ImageButton配合使用 FileUpload控件的方法及属性: 1.SaveAs("要上传到服务器的绝对路径" ...
- cocos2d-x视频控件VideoPlayer的用户操作栏进度条去除(转载)
目前遇到两个问题: (1)视频控件移除有问题,会报异常. (2)视频控件有用户操作栏,用户点击屏幕会停止视频播放. 对于第一个问题,主要是移除控件时冲突引起的,目前简单处理是做一个延时处理,先stop ...
- 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法
今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...
- 百度 flash html5自切换 多文件异步上传控件webuploader基本用法
双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...
随机推荐
- java io读书笔记(2)什么是stream
什么是stream?stream就是一个长度不确定的有序字节序列. Input streams move bytes of data into a Java program from some gen ...
- [原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 浅谈thinkphp中将字符串转换成json数组的方法
这是一部分代码: $client = M("Client");$data = $client->where('user_id ='.$user_id)->select( ...
- c++ 中this底层
成员变量设置在一个结构体中, 操作成员变量的成员函数,其实质上就是拥有一个隐藏的 成员变量结构体的地址指针,俗称this指针.
- UVA 10891 Game of Sum(DP)
This is a two player game. Initially there are n integer numbers in an array and players A and B get ...
- c#经典俄罗斯方块 vs2012开发
把网上两个开源的俄罗斯方块,整合到一起了,开发环境vs2012+.net 4.0,有问题.建议可以加群沟通哦 复古的 c#写的一个俄罗斯方块小游戏,友好的人机交互,具体功能如下: 1.游戏分七个关卡, ...
- 在Visual Studio 2013/2015上使用C#开发Android/IOS安装包和操作步骤
Xamarin 配置手册和离线包下载 http://pan.baidu.com/s/1eQ3qw8a 具体操作: 安装前提条件 1. 安装Visual Studio 2013,安装过程省略,我这里安装 ...
- requireJs和r.js压缩工具
上面release是执行命令 node r.js -o build.js 生成的,需要切换到目录require/tools下面,也就是 有r.js和build.js的目录,才能执行命令 代码目录如上: ...
- 「thunar」给thunar增加搜索文件功能
1.安装catfish sudo apt-get install catfish 2.配置thunar,添加[自定义动作] 打开 Thunar 后,点击 Edit -> Configure cu ...
- jquery tab键转换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...