All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#中TabControl控件应用实例
提高asp.net网站性能的7个方法_[Asp.Net教程]
C#中使用SQL,Server分布式管理对象(SQL
用PHP程序实现从数组里筛选出重复的数据_php资料_编程技术
关于ASP.NET中事务处理和异常处理的说明_[Asp.Net教程]
开发保留标准的浏览器功能的AJAX应用_[AJAX教程]
ASP.NET的一个简单的数据操作类_[Asp.Net教程]
数据库人员手边系列:SQL语法查询文档_[SQL,Server教程]
PHP代码:从数据表里塞选出重复的数据_php资料_编程技术
Transact_SQL小手册(各种sql语句大集合)_[SQL,Server教程]
Reading number is top 10 pictures
girl of HuNan name is LiXiang(湖南辣姐李湘的写真)
The terra-cotta warriors3
开始让人感动,后来......
Sell the barbecue as says father du breul3
教你做读书笔记
可爱的小动物
采访谢楠
The terra-cotta warriors1
Distribution of wealth in China survey status report
程序员的悲哀
Download software ranking
Boxer's Top ten classic battle7
VeryCD电驴(EasyMule) V1.1.9 Build09081
C#与.NET技术平台实战演练
仙剑奇侠传98硬盘WINXP版
都市狐狸姑娘传
Call Of Duty2
Unix video tutorial6
ASP.NET.2.0.XML.高级编程(第3版)
变速齿轮3.26
matrix2
归海一刀 published in(发表于) 2014/1/30 1:01:53 Edit(编辑)
Flex+asp.net上传文件_[Asp.Net教程]

Flex+asp.net上传文件_[Asp.Net教程]

Flex+asp.net上传文件_[Asp.Net教程]

前台Flex文件:UploadSample.mxml,其代码如下所示:

1
2
3
4 global
5 {
6 fontSize : 12;
7 }
8

9
10
11 12 // 先搞 1 个 FileReference
13 private var file:FileReference = new FileReference();
14
15 // 上传状态指示, 和下面的文本框绑定
16 [Bindable]
17 private var stateText:String = "请选择一个文件上传";
18
19 // createChildren 比 creationComplete 事件更早发生, 省的注册事件侦听, 直接在这里写了
20 protected override function createChildren():void
21 {
22 super.createChildren();
23 file.addEventListener(Event.SELECT, file_select);
24 //file.addEventListener(Event.COMPLETE, file_complete);
25 file.addEventListener(ProgressEvent.PROGRESS, file_progress);
26 file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, file_complete);
27 }
28
29 // 选择 1 个文件的事件
30 private function file_select (e:Event):void
31 {
32 stateText = "选择了文件 " + file.name;
33 }
34
35 // 上传完毕后的事件
36 private function file_complete (e:Event):void
37 {
38 stateText = "上传完毕";
39 }
40
41 private function file_progress (e:ProgressEvent):void
42 {
43 stateText = "已上传 " + Math.round(100 * e.bytesLoaded / e.bytesTotal) + "%";
44 }
45 // 先判断一下文件大小, 再上传, FileService.aspx 就是上传地址
46 private function upload ():void
47 {
48 if (file.size > 0)
49 {
50 stateText = "正在上传 " + file.name;
51 var request:URLRequest =
52 new URLRequest("http://localhost:1851/WebSite1/FileService.aspx");
53 file.upload(request);
54 }
55 }
56
57
58 ]]>
59

60
61 62 verticalAlign="middle" horizontalAlign="center" >
63
64
65
66

67
68
69

70

71

72
服务器端asp.net文件:FileService.aspx.cs,其代码如下所示:

1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class FileService : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 string uploadFolder = "upload"; // 上传文件夹
17
18 HttpFileCollection files = Request.Files;
19
20 if (files.Count == 0)
21 {
22 Response.Write("请勿直接访问本文件");
23 Response.End();
24 }
25
26 string path = Server.MapPath(uploadFolder);
27
28 // 只取第 1 个文件
29 HttpPostedFile file = files[0];
30
31 if (file != null && file.ContentLength > 0)
32 {
33 // flash 会自动发送文件名到 Request.Form["fileName"]
34 string savePath = path + "/" + Request.Form["fileName"];
35 file.SaveAs(savePath);
36 }
37 }
38 }
说明:
客户端Flex使用URLRequest对象请求一个服务器端的连接,在服务器端使用HttpFileCollection对象接收客户端的请求。flash 会自动发送文件名到 Request.Form["fileName"]。
效果如下所示:


来源:http://www.cnitblog.com/Lalo





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.