zoukankan      html  css  js  c++  java
  • 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();
            }
  • 相关阅读:
    暑假每周学习进度-7
    暑假每周学习进度-6
    寒假生活05
    寒假生活04
    寒假生活03
    寒假生活02
    寒假生活01
    软件设计师2019模拟小测
    第二周学习记录
    2019秋季学习计划
  • 原文地址:https://www.cnblogs.com/914556495wxkj/p/3555159.html
Copyright © 2011-2022 走看看