一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP.NET教程 - ASP.NET實現大文件上傳功能

ASP.NET實現大文件上傳功能

2020-03-12 12:23hyyweb ASP.NET教程

這篇文章主要為大家詳細介紹了ASP.NET實現大文件上傳功能,解決了 ASP.NET 中的大文件上傳問題,感興趣的朋友可以參考一下

需要下載NeatUpload插件

上傳頁面:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="_Default" %>
 
<%@ Register Assembly="Brettle.Web.NeatUpload" Namespace="Brettle.Web.NeatUpload"
  TagPrefix="Upload" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
   <link href="easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
  <link href="easyui/themes/icon.css" rel="stylesheet" type="text/css" />
  <script src="easyui/jquery.min.js" type="text/javascript"></script>
  <script src="easyui/jquery.easyui.min.js" type="text/javascript"></script>
</head>
<body>
  <form id="form1" runat="server">
  <div class="easyui-panel" style="padding:5px;">
    <Upload:ProgressBar ID="ProgressBar1" runat='server'>
    </Upload:ProgressBar>
   <br />
  <Upload:InputFile ID="AttachFile" runat="server" />
  <br />
  <br />
  <asp:LinkButton ID="BtnUP" runat="server" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="BtnUP_Click">上 傳</asp:LinkButton><br /><br />
  <a href="Down.aspx">查看下載</a>
  </div>
  </form>
</body>
</html>

后臺源碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
protected void BtnUP_Click(object sender, EventArgs e)
  {
    if (AttachFile.HasFile)
    {
      string FileName = this.AttachFile.FileName;//獲取上傳文件的文件名,包括后綴
      string ExtenName = System.IO.Path.GetExtension(FileName);//獲取擴展名
      string SaveFileName = System.IO.Path.Combine(System.Web.HttpContext.Current.Request.MapPath("UpLoads/"), DateTime.Now.ToLongDateString().ToString() + "-" + FileName);//合并兩個路徑為上傳到服務器上的全路徑
      AttachFile.MoveTo(SaveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
      string url = "UpLoads/" + DateTime.Now.ToString("yyyyMMddhhmmss") + ExtenName; //文件保存的路徑
      float FileSize = (float)System.Math.Round((float)AttachFile.ContentLength / 1024000, 1); //獲取文件大小并保留小數點后一位,單位是M
      Response.Write("<script>alert('恭喜您,上傳成功!')</script>");
    }
    else
    {
      Response.Write("<script>alert('請選擇文件!')</script>");
    }
  }

這里直接獲取上傳文件夾文件名稱提供下載

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Down.aspx.cs" Inherits="Down" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <link href="easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
  <link href="easyui/themes/icon.css" rel="stylesheet" type="text/css" />
  <script src="easyui/jquery.min.js" type="text/javascript"></script>
  <script src="easyui/jquery.easyui.min.js" type="text/javascript"></script>
  <style type="text/css">
    .div_style ul li
    {
       list-style-type: decimal;
       border-bottom:1px dashed #E3E3E3;
       margin-bottom:5px;
    }
    .div_style ul li a
    {
      text-decoration: none;
      cursor: pointer;
      font-size: 16px;
    }
  </style>
</head>
<body>
  <form id="form1" runat="server">
  <div class="div_style easyui-panel" style="padding: 5px;">
  <a href="index.aspx">上傳文件</a>
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    <ul id="www_zzjs_net">
      <%if (files.Length == 0) { Label1.Text = "暫無文件"; }
       else
       {
 
         foreach (System.IO.FileInfo item in files)
         {%>
      <li><a href="Default2.aspx?1=<%=item%>">
        <%=item %></a>     <a href="delete.aspx?1=<%=item%>" onclick="javascript:return confirm('確定刪除嗎?');" >刪除附件</a>
      </li>
      <% }
     }%>
    </ul>
  </div>
  <div id="changpage"></div>
  <%--js分頁--%>
<%--<script language="javascript">
  var obj, j;
  var page = 0;
  var nowPage = 0; //當前頁
  var listNum = 25; //每頁顯示<ul>數
  var PagesLen; //總頁數
  var PageNum = 4; //分頁鏈接接數(5個)
  onload = function () {
    obj = document.getElementById("www_zzjs_net").getElementsByTagName("li");
    j = obj.length
    PagesLen = Math.ceil(j / listNum);
    upPage(0)
  }
  function upPage(p) {
    nowPage = p
    //內容變換
    for (var i = 0; i < j; i++) {
      obj[i].style.display = "none"
    }
    for (var i = p * listNum; i < (p + 1) * listNum; i++) {
      if (obj[i]) obj[i].style.display = "block"
    } //歡迎來到站長特效網,我們的網址是www.zzjs.net,很好記,zz站長,js就是js特效,本站收集大量高質量js代碼,還有許多廣告代碼下載。
    //分頁鏈接變換
    strS = '<a href="###" onclick="upPage(0)">首頁</a> '
    var PageNum_2 = PageNum % 2 == 0 ? Math.ceil(PageNum / 2) + 1 : Math.ceil(PageNum / 2)
    var PageNum_3 = PageNum % 2 == 0 ? Math.ceil(PageNum / 2) : Math.ceil(PageNum / 2) + 1
    var strC = "", startPage, endPage;
    if (PageNum >= PagesLen) { startPage = 0; endPage = PagesLen - 1 }
    else if (nowPage < PageNum_2) { startPage = 0; endPage = PagesLen - 1 > PageNum ? PageNum : PagesLen - 1 } //首頁
    else { startPage = nowPage + PageNum_3 >= PagesLen ? PagesLen - PageNum - 1 : nowPage - PageNum_2 + 1; var t = startPage + PageNum; endPage = t > PagesLen ? PagesLen - 1 : t }
    for (var i = startPage; i <= endPage; i++) {
      if (i == nowPage) strC += '<a href="###" style="color:red;font-weight:700;" onclick="upPage(' + i + ')">' + (i + 1) + '</a> '
      else strC += '<a href="###" onclick="upPage(' + i + ')">' + (i + 1) + '</a> '
    } //歡迎來到站長特效網,我們的網址是www.zzjs.net,很好記,zz站長,js就是js特效,本站收集大量高質量js代碼,還有許多廣告代碼下載。
    strE = ' <a href="###" onclick="upPage(' + (PagesLen - 1) + ')">尾頁</a> '
    strE2 = nowPage + 1 + "/" + PagesLen + "頁" + " 共" + j + "條"
    document.getElementById("changpage").innerHTML = strS + strC + strE + strE2
  }
</script>--%>
  </form>
</body>
</html>
 
//下面是后臺代碼
public FileInfo[] files { set; get; }
protected void Page_Load(object sender, EventArgs e)
{
string dirPath = HttpContext.Current.Server.MapPath("~/UpLoads");
if (Directory.Exists(dirPath))
{
DirectoryInfo dir = new DirectoryInfo(dirPath);
files = dir.GetFiles("*.*");
}
if (files.Length == 0) { Label1.Text = "暫無文件"; }
}
 
 
 
//這是新建另一個頁面提供下載的代碼
 
if (Request.QueryString["1"] != null)
{
 
 
string _filename = Request.QueryString["1"].ToString(), _filepath = System.IO.Path.Combine(MapPath("~/UpLoads"), _filename);
if (System.IO.File.Exists(_filepath))
{
Response.Clear();
Response.Buffer = true;
 
Response.AddHeader("Content-Disposition", "attachment;filename=" + _filename);
Response.ContentType = "application/unknow";
Response.TransmitFile(_filepath);
Response.End();
}
}
 
 
 
//這是新建另一個頁面提供刪除操作(后臺)
 
string _filename = Request.QueryString["1"].ToString(), _filepath = System.IO.Path.Combine(MapPath("~/UpLoads"), _filename);
if (System.IO.File.Exists(_filepath))
{
File.Delete(_filepath);
Response.Write("<script language=javascript>alert('刪除成功!');window.location = 'Down.aspx';</script>");
//Response.Redirect("Down.aspx");
}

以上就是本文的全部內容,希望對大家的學習有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本人与黑人做爰视频网站 | 日本wwxx护士| 亚洲欧美日韩精品久久亚洲区 | 69日本人xxxx16—18 | 羲义嫁密着中出交尾gvg794 | 99热久久这里只有精品23 | 黄漫免费观看 | 欧美一级片观看 | 亚洲高清在线视频 | 精品日韩一区二区三区 | 亚洲第成色999久久网站 | 欧美在线视频7777kkkk | 男人免费视频 | 免费高清视频在线观看 | 亚州中文字幕 | 日岳母小说 | 天天做天天玩天天爽天天 | 国产一区二区三区久久小说 | 逼123| 日本人妖视频 | 91大神大战高跟丝袜美女 | 亚洲精品成人在线 | 天天做天天爱天天爽综合网 | 99热资源 | 国产亚洲sss在线播放 | 亚洲国产一区二区三区a毛片 | 波多野结衣 在线播放 | 午夜亚洲WWW湿好爽 午夜想想爱午夜剧场 | 亚洲高清免费在线观看 | 国产白虎 | 日韩一| 亚洲欧美日韩另类精品一区二区三区 | 精品四虎国产在免费观看 | 欧美综合另类 | 色妞女女女女女bbbb | 好姑娘完整版在线观看中文 | 好大用力深一点视频 | 草草免费观看视频在线 | videos护士有奶水 | 啊皇上你好大要知画 | 国产精品aⅴ |