您的位置:首页 > 其它

SWFUpload_v2.2.0.1在win2003.Net3.5下使用心得

2010-10-08 11:26 459 查看
开源项目地址:http://swfupload.org/project
下载地址:http://code.google.com/p/swfupload/
1、将SWFUpload_v2.2.0.1_Samples.zip解开,进入demos/applicationdemo.net目录,该目录为示例的站点。
2、从上级目录拷贝css、swfupload目录到本目录下




3、建立一个upload目录用来存放上传文件,被给予Network Service与写入权限。
4、修改Default.aspx前台代码:
修改以下以颜色标出的各项,特别注意其中的
(1)js引用路径,要用相对路径。如果用绝对路径,则会弹出SWFUpload未定义错误。
(2)upload_url: "upload.aspx",在v2.2.0.1版本里,这里是相对于Default.aspx的路径。看到网上其它文章说是,这里是相对于swfupload.swf的路径,经试验发现不是。
(3)添加了2个按钮,用来将图片存放到服务器的upload目录下,和清除所有上传。
5、在后台代码中添加按钮功能,见下。
6、默认的网站上传到服务器需要.cs文件,如果使用vs2008,想编译成bin,需将App_Code中的Thumbnail.cs拿出来,重新建类。
同时,将Default.aspx、upload.aspx和thumbnail.aspx添加网站的nameplace
示例 后台namespace SoftWeb.uploadme 前台
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SoftWeb.Default" %>

Default.aspx前台代码:
<head id="Head1" runat="server">
<title>SWFUpload Application Demo (ASP.Net 2.0)</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="swfupload/swfupload.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function() {
swfu = new SWFUpload({
// Backend Settings
upload_url: "upload.aspx",
post_params: {
"ASPSESSID": "<%=Session.SessionID %>"
},
// File Upload Settings
file_size_limit: "2 MB",
file_types: "*.jpg",
file_types_description: "JPG Images",
file_upload_limit: "0", // Zero means unlimited
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
file_queue_error_handler: fileQueueError,
file_dialog_complete_handler: fileDialogComplete,
upload_progress_handler: uploadProgress,
upload_error_handler: uploadError,
upload_success_handler: uploadSuccess,
upload_complete_handler: uploadComplete,
// Button settings
button_image_url: "images/XPButtonNoText_160x22.png",
button_placeholder_id: "spanButtonPlaceholder",
button_width: 160,
button_height: 22,
button_text: '<span class="button">Select Images <span class="buttonSmall">(2 MB Max)</span></span>',
button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 10pt; }',
button_text_top_padding: 1,
button_text_left_padding: 5,
// Flash Settings
flash_url: "swfupload/swfupload.swf", // Relative to this file
custom_settings: {
upload_target: "divFileProgressContainer"
},
// Debug Settings
debug: false
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="header">
<h1 id="logo">
<a href="/">首页</a></h1>
<div id="version">
v2.2.0</div>
</div>
<div id="content">
<h2>Application Demo (ASP.Net 2.0) </h2>
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<span id="spanButtonPlaceholder"></span>

<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save Select Images"
Width="150px" />
<asp:Button ID="btnClear" runat="server" Text="Clear Select Images" OnClick="btnClear_Click"
Width="150px" />
</div>
<div id="divFileProgressContainer" style="height: 75px;">
</div>
<div id="thumbnails">
</div>
</div>
</div>
</form>
</body>
</html>

后台Default.aspx代码

protected void Page_Load(object sender, EventArgs e)
{
// Clear the user's session
if (!IsPostBack)
{
Session.Clear();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (Session["file_info"] != null)
{
List<Thumbnail> thumbnails = Session["file_info"] as List<Thumbnail>;
string UploadPath = Server.MapPath("upload/");
foreach (Thumbnail img in thumbnails)
{
FileStream fs = new FileStream(UploadPath + img.ID + ".jpg", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(img.Data);
bw.Close();
fs.Close();
}
Session.Clear();
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
Session.Clear();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: