您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 企业财务 > NeatUpload操作文档
1.引入bin文件(可以到neatupload官网下载,也可以到教育厅申报系统中找)2.将控件加入到工具栏在工具栏中任选一控件点鼠标右键,如图:(也可在工具中找到“选择工具箱项”)3.加入neatuplaod这个文件夹(可以到neatupload官网下载,也可以到教育厅申报系统中找)4.Webconfig的配置(3个地方)configSections配置节下配置:!--配置NeatUploadsectionGroup配置节--sectionGroupname=system.websectionname=neatUploadtype=Brettle.Web.NeatUpload.ConfigSectionHandler,Brettle.Web.NeatUploadallowLocation=true//sectionGroupsystem.web配置节下配置:!--配置NeatUploadneatUpload配置节--neatUploaduseHttpModule=TruemaxNormalRequestLength=4096maxRequestLength=2097151defaultProvider=FilesystemUploadStorageProviderprovidersaddname=FilesystemUploadStorageProvidertype=Brettle.Web.NeatUpload.FilesystemUploadStorageProvider,Brettle.Web.NeatUpload//providers/neatUploadhttpModules配置节下配置:!--配置NeatUploadhttpModules配置节--!--如果不加这httpmodules,进度条不显示--addname=UploadHttpModuletype=Brettle.Web.NeatUpload.UploadHttpModule,Brettle.Web.NeatUpload/注意:配置第二个的时候,即:~!--配置NeatUploadneatUpload配置节--配置完后会在neatUpload出现蓝色波浪,提示system.web的子元素无效。无需纠结,它本身是起作用的。5.页面代码%@RegisterAssembly=Brettle.Web.NeatUploadNamespace=Brettle.Web.NeatUploadTagPrefix=Upload%linkhref=../../../../NeatUpload/default.cssrel=stylesheettype=text/css/scripttype=text/javascriptlanguage=javascriptfunctionToggleVisibility(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:InputFileID=AttachFilerunat=server/asp:ButtonID=btnAddrunat=serverText=上传OnClientClick=ToggleVisibility('ProgressBar','on')OnClick=btnAdd_Click/asp:LabelID=Label10runat=serverText=*最大上传为4MForeColor=Red/asp:Labeldivid=ProgressBarstyle=display:none//……进度条Upload:ProgressBarID=pbProgressBarrunat='server'Inline=trueWidth=800pxHeight=50pxAllowTransparency=False/Upload:ProgressBar/div6.页面后台代码范例:protectedvoidbtnAdd_Click(objectsender,EventArgse){if(!string.IsNullOrEmpty(AttachFile.FileName)){intProjectID=this.CurrentProjectID;stringFileName=this.AttachFile.FileName;//获取上传文件的文件名stringFileNameExtenter=System.IO.Path.GetExtension(FileName).ToLower();;//获取扩展名if(AttachFile.FileContent.Length4096*1024&&AttachFile!=null){Page.ClientScript.RegisterStartupScript(this.GetType(),DateTime.Now.Ticks.ToString(),scriptalert('文件大于4M,不能上传')/script);StreamSr=AttachFile.FileContent;//创建数据流对象Sr.Close();//this.Response.Write(scriptlanguage=javascriptalert('文件大于4M,不能上传!');history.go(-1);/script);return;}if(AttachFile.FileContent.Length==0){this.Response.Write(scriptlanguage=javascriptalert('空文件,不能上传!');history.go(-1);/script);StreamSr=AttachFile.FileContent;//创建数据流对象Sr.Close();return;}if(AttachFile!=null&&FileName!=null){if(FileNameExtenter==.doc){StreamSr=AttachFile.FileContent;//创建数据流对象intupLength=Convert.ToInt32(AttachFile.ContentLength);byte[]b=newbyte[upLength];//定义byte型数组Sr.Read(b,0,upLength);//数据存放到b数组对象实例中,其中0代表数组指针的起始位置,uplength表示要读取流的长度(指针的结束位置)BinaryContent=newBinary(b);Attachment_attachment=newAttachment();_attachment.Entity=ReportProject;_attachment.EntityID=ProjectID;_attachment.Content=Content;_attachment.FileName=FileName;_attachment.UsedFlag=1;_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(),scriptalert('附件上传成功!请检查!')/script);this.gv.DataBind();//ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(),DateTime.Now.Ticks.ToString(),scriptwindow.alert('附件上传成功!');window.location.href=window.location.href;/script,false);//ProgressBar.Visible=false;return;}else{this.Response.Write(scriptlanguage=javascriptalert('不能上传word以外文件!请先将文件将转换为word(后缀名必须为doc)形式再上传');history.go(-1);/script);StreamSr=AttachFile.FileContent;//创建数据流对象Sr.Close();return;}}}else{this.Response.Write(scriptlanguage=javascriptalert('请选择上传文件');history.go(-1);/script);return;}}7.注意的地方1.当需要报错的时候,在报错的函数必须有StreamSr=AttachFile.FileContent;//创建数据流对象Sr.Close();看似多此一举,但是不写就会有错,2.而且在进度条走完以后后台代码才会执行,故而如果文件过大,待文件上传完毕后提示文件过大会影响用户体验,这个问题待解决3)知识点:用asp:FileUpload控件时后台代码中FileUpload.SaveAs(path);等同于:用Upload:InputFile控件时后台代码中this.AttachFile.MoveTo(path,Brettle.Web.NeatUpload.MoveToOptions.Overwrite);8:效果展示(上传足够大的文件,效果才会明显):
本文标题:NeatUpload操作文档
链接地址:https://www.777doc.com/doc-2889527 .html