加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex 上传文件与asp.net配合

发布时间:2020-12-15 04:05:53 所属栏目:百科 来源:网络整理
导读:转自:http://hi.baidu.com/seriawei/item/e7cdbc96b367e8a9cd80e5ce MXML里的代码: ?xml version="1.0" encoding="utf-8"? s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"? ?? xmlns:s="library://ns.adobe.com/flex/spark"? ?? xmlns:mx="library://ns

转自:http://hi.baidu.com/seriawei/item/e7cdbc96b367e8a9cd80e5ce

MXML里的代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"?
?? xmlns:s="library://ns.adobe.com/flex/spark"?
?? xmlns:mx="library://ns.adobe.com/flex/mx" width="250" height="50">
?<s:layout>
??<s:BasicLayout/>
?</s:layout>
?<fx:Declarations>
??<!-- 将非可视元素(例如服务、值对象)放在此处 -->
?</fx:Declarations>
?
?<fx:Script>
??<![CDATA[
???import mx.controls.Alert;
???import mx.events.FlexEvent;
???

???protected function ShowBrose():void
???{
????var file:FileReference=new FileReference();
????file.addEventListener(Event.SELECT,Selected);
????file.addEventListener(ProgressEvent.PROGRESS,Updating);
????file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,Completed);
????file.browse();
???}
???protected function Selected(e:Event):void
???{
????Button_up.enabled=false;
????(e.target as FileReference).upload(new URLRequest("upload.aspx"),(e.target as FileReference).name,false);
???}
???
???protected function Updating(e:ProgressEvent):void
???{
????ProgressBar_pro.setProgress(e.bytesLoaded,e.bytesTotal);
???}
???
???protected function Completed(e:DataEvent):void
???{
????ProgressBar_pro.label="上传完成";?
???}

??]]>
?</fx:Script>
?<mx:ProgressBar x="0" y="7" width="100%" height="34" id="ProgressBar_pro" mode="manual"/>
?<s:Button x="205" y="19" label="上传" click="ShowBrose()" width="44" id="Button_up"/>
</s:Group>

?

ASP.NET "upload.aspx"文件 Page_Load 事件代码:

?protected void Page_Load(object sender,EventArgs e)
??? {
??????? HttpFileCollection files = Request.Files;
??????? if (files.Count == 0)
??????? {
??????????? Response.Write("请不要直接访问该页");
??????????? Response.End();
??????? }
??????? else
??????? {
??????????? HttpPostedFile file = files[0];
??????????? file.SaveAs(Server.MapPath("upfiles") + "/" + Request.Form["fileName"]);
??????? }

??? }

修改上传文件大小限制:

web.config

<system.web> ??<httpRuntime maxRequestLength="123321" executionTimeout="900" /> ?</system.web>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读