aspnet2014-07-31 21:00:59 6423
Flex端代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="windowedapplication1_creationCompleteHandler(event)"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
[Bindable]
private var stateText:String="文件名:";
[Bindable]
private var isShow:Boolean=false;
private var isSelect:Boolean=false;
private var file:FileReference = new FileReference();
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
file.addEventListener(Event.SELECT, file_select);
file.addEventListener(Event.COMPLETE, file_complete);
file.addEventListener(ProgressEvent.PROGRESS, file_progress);
}
private function file_select (e:Event):void {
stateText = "文件名: " file.name;
isSelect=true;
isShow=true;
}
private function file_complete (e:Event):void {
stateText = "上传完毕";
PopUpManager.removePopUp(this);
mtxt.text="Images/FileImage/" file.name;
}
private function file_progress (e:ProgressEvent):void {
stateText = "已上传 " Math.round(100 * e.bytesLoaded / e.bytesTotal) "%";
}
private function upload ():void {
if(isSelect==false){
stateText="请先选择文件";
return;
}
if (file.size > 0) {
stateText = "正在上传 " file.name;
var request:URLRequest = new URLRequest("../../LegendsFileHandler.aspx");
file.upload(request);
}
}
]]>
</fx:Script>
<s:Group left="10" top="10">
<s:Label left="10" top="10" text="{stateText}"/>
<s:Button left="10" top="30" label="选择" click="file.browse();"/>
<s:Button left="110" top="30" label="上传" visible="{isShow}" click="upload();"/>
<s:TextInput width="100%" top="50" id="mtxt"/>
</s:Group>
</s:Application>ASP.NET端代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MieMie
{
public partial class LegendsFileHandler : System.Web.UI.Page
{
string uploadFolder = "Image/";
protected void Page_Load(object sender, EventArgs e)
{
HttpFileCollection files = Request.Files;
if (files.Count == 0)
{
Response.End();
}
string path = Server.MapPath(uploadFolder);
HttpPostedFile file = files[0];
if (file != null && file.ContentLength > 0)
{
string savePath = path "/" Request.Form["fileName"];
file.SaveAs(savePath);
}
}
}
}
彭亚欧个人博客原创文章,转载请注明出处
文章关键词:ASP.NET与Flex图片上传,图片上传,flex图片上传
文章固定链接:https://www.pengyaou.com/legendsz/server/aspnet/NjY=.html
上一篇 CSS3日食效果