您的位置:首页 > 移动开发 > Objective-C

带进度条的文件上传控件使用小结

2006-03-14 13:49 447 查看
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
<script type="text/javascript"><!--
google_ad_client = "pub-0380950997514063";
/* 横向五个 */
google_ad_slot = "7194863803";
google_ad_width = 728;
google_ad_height = 15;
// --></script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

一、上传界面内容

选择文件:

   上 传
选择文件:
   上 传
 
说明:为了能正确显示,把原有asp.NET按钮控件换成了HTML的按钮控件

二、后台代码

       1.page_load部分内容

            private void Page_Load(object sender, System.EventArgs e)
             {
                      // 在此处放置用户代码以初始化页面
                      UpLoadHelper helper = new UpLoadHelper();   
                      helper.RegisterProgressBar(bt_save.UniqueID);
                      string path = Path.Combine(Server.MapPath("."),"loadfile");
                      if(!Directory.Exists(path))
                       {
                          Directory.CreateDirectory(path);
                      }
                       helper.UploadFolder = path;  
                      bind();
             }

     2.加入了自定义的显示上传文件夹的文件列表方法

           public void bind()
           {
                  string path = Path.Combine(Server.MapPath("."),"loadfile");
                  if(!Directory.Exists(path))
                   {
                         Directory.CreateDirectory(path);
                   }
                  Table1.Rows.Clear();
                  foreach(string filename in Directory.GetFiles(path))
                  {
                         TableRow r = new TableRow();
                         TableCell c = new TableCell();
                         c.Text = filename;
                         r.Cells.Add(c);
                        Table1.Rows.Add(r);
                }
          }

    3.批量上传文件的代码

     UpLoadHelper helper = new UpLoadHelper();
    
    string path = Path.Combine(Server.MapPath("."),"loadfile");
       
    foreach(UpLoadFile file in helper.GetUploadFileList("file1"))
    {
     file.SaveAs(Path.Combine(path,Path.GetFileName(file.FileName)));     
    }
    bind();

4.单个文件上传的代码

UpLoadHelper helper = new UpLoadHelper();
   
   string path = Path.Combine(Server.MapPath("."),"loadfile");
   UpLoadFile file = helper.GetUploadFile("s_file");
   file.SaveAs(Path.Combine(path,Path.GetFileName(file.FileName))); 
   bind(); 

三、说明
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息