zoukankan      html  css  js  c++  java
  • 上传文件带超连接并计算个数

         protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    Session["demo"] = new List<String>();
                }
            }
            private static int f;//给全局变量并赋值0,static可以保存值
          
         
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                  string FileName = FileUpload2.PostedFile.FileName;
                  if (FileName == "")
                  {
                      Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), string.Format("<script>alert('上传文件不能为空!')</script>"));
                  }
                  else
                  {
                      string file_KB = FileUpload2.PostedFile.ContentLength.ToString() + "KB<br>";//获取文件大小
                      string file = FileUpload2.FileName;//获取上传文件名字
    
                      string URL = "http://amid01110/456/" + file + " ";
    
    
                      List<string> list = Session["demo"] as List<string>;
                      Session["demo"] = list;
                      string lntext = "<a  href='" + URL + "'  >" + file + "</a>" + "大小" + file_KB + "上传文件成功";
    
    
    
                      Label1.Text += Label1.Text.Length > 0 ? "<br />" + lntext : lntext;
                      f++;//添加的个数
                      Label2.Text = f.ToString();
                  }
            }

    前台 

      <div>
        <asp:FileUpload ID="FileUpload2" runat="server" />
        <asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button1_Click" />
        共上传<asp:Label ID="Label2" runat="server"></asp:Label><br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        </div>

     后台:方法二

       protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    ViewState["demo"] = 0;
                }
            }
            
          
         
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                
                  string FileName = FileUpload2.PostedFile.FileName;
                  if (FileName == "")
                  {
                      Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), string.Format("<script>alert('上传文件不能为空!')</script>"));
                  }
                  else
                  {
                      string file_KB = FileUpload2.PostedFile.ContentLength.ToString() + "KB<br>";//获取文件大小
                      string file = FileUpload2.FileName;//获取上传文件名字
                      ViewState["demo"] = Convert.ToInt32(ViewState["demo"]) + 1;//ViewState["demo"]获取个数
    
                      string URL = "http://amid01110/456/" + file + " ";
    
    
                     
                      string lntext = "<a  href='" + URL + "'  >" + file + "</a>" + "大小" + file_KB + "上传文件成功";
    
    
    
                      Label1.Text += Label1.Text.Length > 0 ? "<br />" + lntext : lntext;
                     
                      Label2.Text = ViewState["demo"].ToString();
                  }
            }
  • 相关阅读:
    2018.7.9 模拟赛
    树状数组||归并排序求逆序对+离散化 nlogn
    LCS nlogn
    孤岛营救问题
    [POJ 3621] Sighting Cows
    树状数组求LIS
    nlogn求逆序对&&陌上花开
    最长可重区间集
    LCA模板
    [BZOJ] 4196 [Noi2015]软件包管理器
  • 原文地址:https://www.cnblogs.com/914556495wxkj/p/3566918.html
Copyright © 2011-2022 走看看