当前位置:编程学习 > C#/ASP.NET >>

批量上传文件

文章红字出为标注的问题    
<%@ Page Title="" Language="C#" MasterPageFile="~/back/backdao.master" AutoEventWireup="true" CodeBehind="wenjian.aspx.cs" Inherits="Library1.back.wenjian" %>
<asp:Content ID="Content1" ContentPlaceHolderID="daoneirong" runat="server">
  
    <table style="width:100%;"  >
        <tr>
            <td>
                 </td>
            <td>
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                <asp:Button ID="BTchuan" runat="server" Text="上传文件" />
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                <asp:Button ID="BTxuan" runat="server" Text="选择文件" />
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                <asp:Label ID="Lxian" runat="server"></asp:Label>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td>
                 </td>
            <td>
                <table style="width:100%;" id="F" runat="server" >
                    <tr runat="server" id="F" >
                        <td>
                            <asp:FileUpload ID="FileUpload1" runat="server" />
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                 </td>
        </tr>
    </table>
  
</asp:Content>

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.UI.HtmlControls;
public partial class wenjian : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SFUPC();
        }
    }
    protected System.Web.UI.HtmlControls.HtmlTableRow trButton;
    protected void BTchuan_Click(object sender, EventArgs e)
   {
   
   }
    protected void BTxuan_Click(object sender, EventArgs e)
   { 
   
   }
    private void SFUPC()//保存当前上传文件控件集到缓存
   {
       ArrayList AL = new ArrayList();//创建动态增加数组
       foreach (Control C in F.Controls)//in F.Control什么意思F是什么
       {
           if (C.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlTableRow")
           {
               HtmlTableCell HTC = (HtmlTableCell)C.Controls[0];
               foreach (Control FUC in HTC.Controls)
               {
                   if (FUC.GetType().ToString == "System.Web.UI.WebControls.FileUpload")
                   {
                       FileUpload FU = (FileUpload)FUC;
                       AL.Add(FU);
                   }
               }
           }
       }
       Session.Add("FilesControls", AL);
   }
    private void InsertC()//用于添加控件一个文件的上传控件
    {
        ArrayList AL = new ArrayList();
        this.F.Rows.Clear();
        GetInfo();
        HtmlTableRow HTR = new HtmlTableRow();
        HtmlTableCell HTC = new HtmlTableCell();
        HTC.Controls.Add(new FileUpload());
        HTR.Controls.Add(HTC);
        F.Rows.Add(HTR);
        SFUPC();
    }
    private void GetInfo()//读取缓存中存在的上传文件的集
    {
        ArrayList AL = new ArrayList();
        if (Session["FilesControls"] !=null)
        {
            AL = (System.Collections.ArrayList)Session["FilesControls"];
            for (int i = 0; i < AL.Count; i++)
            {
                HtmlTableRow HTR = new HtmlTableRow();
                HtmlTableCell HTC = new HtmlTableCell();
                HTC.Controls.Add(System.Web.UI.WebControls.FileUpload AL[i]);//这句该怎么写                HTR.Controls.Add(HTC);
                F.Rows.Add(HTR);
            
        }
    }
    private void UpFile()
    {
        string FilePath = Server.MapPath("./") + "File";
        HttpFileCollection HTC = Request.Files;
        for (int i = 0; i < HTC.Count; i++)
        {
            HttpPostedFile UserHPF = HTC[i];
            if (UserHPF.ContentLength > 0)
            {
                UserHPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(UserHPF.FileName));
            }
        }
        if(Session["FileConrrol"]!=null)
        {
          Session.Remove("FilesControl");
        }
    }
}
ASP ArrayList --------------------编程问答--------------------      <table style="width:100%;" id="F" runat="server" >                     <tr runat="server" id="F" > 

这里两个ID="F" 的 runat="server" 不出错? --------------------编程问答-------------------- 去一个依旧不行。请问)(Control C in F.Controls)这里的F是哪的   --------------------编程问答-------------------- id="F" runat="server" 这里不是F吗? --------------------编程问答-------------------- 识别不了说是上下文不存在F --------------------编程问答--------------------
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,