SharePoint上传循环添加label并获取上传文件名字的扩展名和文件大小(Session["demo"] = new List<Label>();方法实现)

前台

<div>
    <asp:Button ID="Button2" runat="server"   OnClick="Button2_Click" Text="添加label" />
    <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Panel ID="Panel1" runat="server" ViewStateMode="Enabled"></asp:Panel>
    <asp:HiddenField ID="HiddenField1" runat="server" />
        <br />
        个数<br />
        <asp:Label ID="Label3" runat="server"></asp:Label>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />获取的数值只要是传给label都可以正常显示<br />
        <asp:Label ID="Label2" runat="server"></asp:Label>
        </div>
    

后台

  protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["demo"] = new List<Label>();
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            string file_KB = FileUpload1.PostedFile.ContentLength.ToString() + "KB<br>";//获取文件大小
            string file = FileUpload1.FileName;//获取上传文件名字

            string URL = "http://amid01110/456/" + file + " ";

            string lntext = "<a  href='" + URL + "'  >" + file + "</a>" + "大小" + file_KB + "上传文件成功";
            List<Label> list = Session["demo"] as List<Label>;
            Label l = new Label();
            l.ID = "lbl";
            l.Text = lntext + "<br>";
            list.Add(l);
            Session["demo"] = list;
            foreach (Label item in list)
            {
                Panel1.Controls.Add(item);
            }
            int max = list.Count;
            List<string> lavlist = new List<string>();
            foreach (Label item in list)
            {
                lavlist.Add(item.Text);
            }

            string strValue = "";

            for (int i = 0; i < lavlist.Count; i++)
            {
                strValue += lavlist[i];
            }
            Label2.Text = strValue;
            
            Label3.Text = lavlist.Count.ToString();
        }
原文地址:https://www.cnblogs.com/914556495wxkj/p/3555159.html