Hopes

          Start Here..

           

          ASP.NET中如何使用SWFUpload上傳文件

          ASP.NET中如何使用SWFUpload上傳文件

          ASP.NET中如何使用SWFUpload上傳文件來源:網絡轉摘 作者:佚名 瀏覽: 1784 次 2009-2-20 17:44:53

          前陣子有人提到這個上傳工具,小弟沒玩過就給它抓下來試試
          SWFUpload可以支援多檔上傳功能,還不錯用,小弟分享一下試用的結果

          首先要將官網的Demo Sample抓下來,如下所示:

          SWFUpload下載網址:http://swfupload.googlecode.com
          SWFUpload 下載檔案:SWFUpload-Samples v2.1.0.Release.zip

          在\SWFUpload Samples v2.1.0\demos\applicationdemo.net目錄裡有下列檔案



          接下來只要修改Default這支程式就可以了..我 只增加了儲存選取檔案的功能..

          和清除目前選取檔案的功能..更多的功能就要自己去修 改了...

          asp.net(c#)

          Default.aspx
          view plaincopy to clipboardprint?
          <%@ Page Language="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <htmlxmlns="http://www.w3.org/1999/xhtml">
          <headrunat="server">
          <title>SWFUpload Revision v2.1.0 Application Demo (ASP.Net 2.0)</title>
          <linkhref="css/default.css"rel="stylesheet"type="text/css"/>
          <scripttype="text/javascript"src="swfupload/swfupload.js"></script>
          <scripttype="text/javascript"src="js/handlers.js"></script>
          <scripttype="text/javascript">
          var swfu;
          window.onload = function () {
          swfu = new SWFUpload({
          // Backend Settings
          upload_url: "upload.aspx", // Relative to the SWF file
          post_params : {
          "ASPSESSID" : "<%=Session.SessionID %>"
          },

          // File Upload Settings
          file_size_limit : "2048", // 2MB
          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,

          // Flash Settings
          flash_url : "swfupload/swfupload_f9.swf", // Relative to this file

          custom_settings : {
          upload_target : "divFileProgressContainer"
          },

          // Debug Settings
          debug: false
          });
          }
          </script>
          </head>
          <body>
          <formid="form1"runat="server">
          <divid="header">
          <h1id="logo"><ahref="../">SWFUpload</a></h1>
          <divid="version">v2.1.0 Beta</div>
          </div>


          <divid="content">
          <h2>Application Demo (ASP.Net 2.0)</h2>

          <divid="swfu_container"style="margin: 0px 10px;">
          <div>
          <buttonid="btnBrowse"type="button"style="padding: 5px;"onclick="swfu.selectFiles(); this.blur();"><imgsrc="images/page_white_add.png"style="padding-right: 3px; vertical-align: bottom;"alt="Add Icon"/>Select Images <spanstyle="font-size: 7pt;">(2 MB Max)</span></button>
          <asp:ButtonID="btnSave"runat="server"OnClick="btnSave_Click"Text="Save Select Images"Width="150px"/>
          <asp:ButtonID="btnClear"runat="server"Text="Clear Select Images"OnClick="btnClear_Click"Width="150px"/></div>
          <divid="divFileProgressContainer"style="height: 75px;"></div>
          <divid="thumbnails"></div>
          </div>
          </div>
          </form>
          </body>
          </html>

          Default.aspx.cs
          using System;
          using System.Data;
          using System.Configuration;
          using System.Collections;
          using System.Web;
          using System.Web.Security;
          using System.Web.UI;
          using System.Web.UI.WebControls;
          using System.Web.UI.WebControls.WebParts;
          using System.Web.UI.HtmlControls;
          using System.Collections.Generic;
          using System.IO;

          public partial class _Default : System.Web.UI.Page
          {
          protectedvoid Page_Load(object sender, EventArgs e)
          {
          // Clear the user's session
          if (!IsPostBack)
          {
          Session.Clear();
          }
          }
          protectedvoid 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();
          }
          }
          protectedvoid btnClear_Click(object sender, EventArgs e)
          {
          Session.Clear();
          }
          }

          posted on 2012-12-04 16:40 ** 閱讀(261) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           

          導航

          統(tǒng)計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 崇礼县| 黑龙江省| 邹城市| 新乐市| 玛曲县| 威信县| 漠河县| 宝兴县| 克什克腾旗| 通道| 宁安市| 河池市| 徐州市| 德化县| 鹤峰县| 湄潭县| 永平县| 廉江市| 洛扎县| 平度市| 长泰县| 黔东| 新宾| 资源县| 凌云县| 邢台县| 罗城| 青岛市| 鲜城| 保康县| 北宁市| 甘肃省| 营山县| 阜康市| 云安县| 晋中市| 延川县| 景宁| 冀州市| 东港市| 定陶县|