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上传控件实现文件上传的进度条的更多相关文章

  1. 在EasyUI项目中使用FileBox控件实现文件上传处理

    我在较早之前的随笔<基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用>Web框架介绍中介绍了基于Uploadify的文件上传操作,免费版本用的是J ...

  2. 利用bootsrap控件 实现文件上传功能

    源代码实例:https://github.com/kartik-v/bootstrap-fileinput 一.jsp页面 <%@ page language="java" ...

  3. Js获取file上传控件的文件路径总结

    总结一个获取file上传控件文件路径的方法 firefox由于保护机制只有文件名,不能获取完整路径. document.getElementById('file').onchange = functi ...

  4. jquery本地上传预览扩展(隐藏上传控件单击图片上传支持ie!!)

    我用到的原材料地址:http://www.cnblogs.com/leejersey/p/3660202.html 修改后: /// <reference path="../../Js ...

  5. 037. asp.netWeb用户控件之五使用用户控件实现文件上传功能

    fileUpload.ascx代码: <%@ Control Language="C#" AutoEventWireup="true" CodeFile= ...

  6. WebForm之FileUpload控件(文件上传)

    FileUpload控件要与Button.LinkButton.ImageButton配合使用 FileUpload控件的方法及属性: 1.SaveAs("要上传到服务器的绝对路径" ...

  7. cocos2d-x视频控件VideoPlayer的用户操作栏进度条去除(转载)

    目前遇到两个问题: (1)视频控件移除有问题,会报异常. (2)视频控件有用户操作栏,用户点击屏幕会停止视频播放. 对于第一个问题,主要是移除控件时冲突引起的,目前简单处理是做一个延时处理,先stop ...

  8. 因用了NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误的解决方法

    今天遇到一个问题,就是“NeatUpload大文件上传控件而导致Nonfile portion > 4194304 bytes错误”,百度后发现了一个解决方法,跟大家分享下: NeatUploa ...

  9. 百度 flash html5自切换 多文件异步上传控件webuploader基本用法

    双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...

随机推荐

  1. linux_x86_64 blat安装

    blatSrc35.zip下载地址:http://users.soe.ucsc.edu/~kent/src/ 对于下载好的源代码安装包blatSrc35.zip,需进行编译,安装过程如下: 1.用un ...

  2. UITableView——点击某一行移动到指定位置

    选中某一行后想要tableView自动滚动使得选中行始终处于table的top.middle或者bottom,使用以下方法中的一个就可以实现: [tableView scrollToRowAtInde ...

  3. C++Primer 第十二章

    //1.标准库提供了两种智能指针类型来管理动态对象,均定义在头文件memory中,声明在std命名空间. // shared_ptr:允许多个指针指向同一个对象. // unique_ptr:独占所指 ...

  4. Lintcode: Route Between Two Nodes in Graph

    Given a directed graph, design an algorithm to find out whether there is a route between two nodes. ...

  5. ruby初步学习中遇到的错误

    print <<off This is the second way of creating here document ie. multiple line string; off 报错: ...

  6. drop,delete,truncate区别

    drop,delete,truncate区别 drop-->删除少量信息   eg:drop table 表名: delete-->删除某些数据   eg:delete from 表名: ...

  7. logstash5.x改变

    5.x版本 logstash中 elasticsearch插件的workers,无法配置大于1,会提示 This plugin uses the shared and doesn't need thi ...

  8. JSP-01-搭建Web应用环境

    一.搭建Web应用环境 Tomcat 下载会有两种版本,安装版和解压版,这里以解压版为例 Web服务: 是实现“基于Web无缝集成”的目标而提出的全新概念,希望通过Web服务能够实现不同的系统之间的相 ...

  9. 【Install】我是如何安装Linux类系统的

    安装系统:ubuntu12.04 i386 DVD U盘启动12.04live系统   连线,设置连接 安装系统到硬盘   “语言支持”,更新   安装gnome经典界面 sudo apt-get i ...

  10. Java图像文件的读写

    读取bmp文件到BufferedImage中File file2 = new File("c:\\testimages\\tttt" + ".bmp");// ...