標籤

C# (4) asp.new (3) R (2) Delphi (1) Dos (1) english (1) music (1)

2012年11月27日 星期二

Asp.net和C#:檔案上傳元件

Asp.net和C#:檔案上傳元件
最常見的為Visual Studio內建的FILEUPLOAD和外卦的SWFUPLOAD。
由於本人開發環境是Visual Studio 2005 ( .NET Framework 2.0),
在此環境下:
一個FILEUPLOAD一次只能上一個檔案(較新的Visual Studio 己可以次上傳多個),
而SWFUPLOAD一次可以上傳多個檔案(但不是內建,設定麻煩)。
因此在這裡的SWFUPLOAD就比FILEUPLOAD強一些。

SWFUPLOAD:由SWF和JS完成檔名LOOP的上傳動作。
1.在 SwfUpload 官網中的External links/Demos中可以看到php下SWFUPLOAD的範例
2.在Featured/Downloads下可下載asp.net C#的範例,範例為產生縮圖。
若要要有上傳的動做需自行手寫,這就要看說明書的。
3.說明書:SWFUpload 使用详解
//upload.aspx.cs // Get the data
      HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
      string file_path = Server.MapPath("~/upload/");
      if (!Directory.Exists(file_path)) { Directory.CreateDirectory(file_path); }
      Request.Files["Filedata"].SaveAs(file_path + Request.Files["Filedata"].FileName);//存圖

http://blog.csdn.net/lfp0202/article/details/5800745
SWFUpload V2.2.0 说明文档
SWFUpload v2.2.0.1 中文帮助手册

SWFUpload 英文说明文档
http://demo.swfupload.org/Documentation/
http://www.dotblogs.com.tw/puma/archive/2008/07/16/4504.aspx

http://www.cnblogs.com/hinroe/archive/2011/01/18/1938738.html http://edu.save95.cn/index.php/video/index/14978
SWFUpload 未經定義
http://yrbrlono.blogspot.tw/2011/06/swfupload.html http://www.blueshop.com.tw/board/FUM20041006161839LRJ/BRD200712191119337ET/1.html http://niunan.iteye.com/blog/1343553
http://blog.niunan.net/show.php?id=364
http://sholfen.pixnet.net/blog/post/38230094-%E5%A4%9A%E6%AA%94%E6%A1%88%E4%B8%8A%E5%82%B3%EF%BC%9A%E4%BD%BF%E7%94%A8swfupload
http://topic.csdn.net/u/20100406/15/347649c5-8b74-4c2d-95b8-ec931a666a89.html

http://www.dotblogs.com.tw/chhuang/archive/2008/02/23/1093.aspx
http://chainchung.pixnet.net/blog/post/17177164-%E7%B6%B2%E8%B7%AF%E7%9B%B8%E7%B0%BF%E5%AF%A6%E4%BD%9C%E6%96%B9%E5%BC%8F
SWFUpload使用指南
官網
https://code.google.com/p/swfupload/wiki/v250Beta1

3.
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save Select Images" Width="150px" />

xmlns="http://www.w3.org/1999/xhtml"
    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();
                  }
}
=== FileUpload ==========

.aspx page
   1: <form id="form1" runat="server">

   2: <div>

   3:     <asp:FileUpload ID="FileUpload1" runat="server" /><BR>

   4:     <asp:FileUpload ID="FileUpload2" runat="server" /><BR>

   5:     <asp:FileUpload ID="FileUpload3" runat="server" /><BR>

   6:     <asp:FileUpload ID="FileUpload4" runat="server" /><BR>

   7:     <asp:FileUpload ID="FileUpload5" runat="server" /><BR>

   8:     <asp:FileUpload ID="FileUpload6" runat="server" /><BR>

   9:     <asp:FileUpload ID="FileUpload7" runat="server" /><BR>

  10:     <asp:FileUpload ID="FileUpload8" runat="server" /><BR>

  11:     <asp:FileUpload ID="FileUpload9" runat="server" /><BR>

  12:     <asp:FileUpload ID="FileUpload10" runat="server" /><BR>

  13:     <asp:Button ID="Button1" runat="server" Text="上傳(總合需小於10MB)" OnClick="Button1_Click"  style="width: 150px"/>   

  14:       <input id="btnCancel" type="button" value="取消" onclick="parent.closePopWindow();" style="width: 55px" class="submit_b" />

  15: >

  16:     <asp:Label ID="Label1" runat="server" Text=""></asp:Label>  

  17:     

  18: </div>

  19: </form>

.cs page


   1: protected void Button1_Click(object sender, EventArgs e) {

   2:     HttpPostedFile myFL;

   3:     Label1.Text = "";

   4:     string Archive = Request.QueryString["Archive"].ToString();

   5:     string savePath = Server.MapPath("~/") + "Files/" + Archive + "/";

   6:  

   7:     //建立物件案例。(取得目前的工作目錄、建立、移動、刪除、檢查是否存在和顯示資料夾清單)

   8:     DirectoryInfo objDirectoryInfo = new DirectoryInfo(savePath);

   9:     //如果該目錄不存在時。 //新增目錄。

  10:     if (!objDirectoryInfo.Exists) objDirectoryInfo.Create();

  11:  

  12:  

  13:     for (int i = 0; i < ((int)Request.Files.Count); i++) {

  14:         myFL = Request.Files[i];

  15:  

  16:         if (myFL.ContentLength > 0) {

  17:             ////----透過下面的方法,只取出上傳檔案的檔名。

  18:             string UploadFileName = Path.GetFileName(myFL.FileName);

  19:             //---------------------------------------------------------------------------------------------

  20:             Label1.Text = "<br>第" + (i + 1) + "檔案:" + UploadFileName + "上傳中...";

  21:  

  22:             //—註解:「目錄路徑」與「檔案名稱」,兩者都要!

  23:             myFL.SaveAs(savePath + UploadFileName);

  24:  

  25:         }

  26:     }

  27:     Label1.Text = "<br>上傳結束";

  28:     string script1 = "<script language=\"javascript\" type=\"text/javascript\">parent.__doPostBack('','RELOAD');</script>";

  29:  

  30:     Response.Write(script1);

  31:  

  32: }





參考:
FileUpload:Mis例子、錯誤(斷線)、斷線修正(web.config)其他
ASP.NET 檔案上傳的兩三事
ASP.NET』同時多檔案上傳 - 使用 FileUpload 元件


===NeatUpload
[ASP.NET] 檔案上傳 - NeatUpload - 顯示上傳比例 (ProgressBar)

沒有留言:

張貼留言