FileUp.aspx tidak
1<%@ Halaman bahasa="c#" Codebehind="FileUp.aspx.cs" AutoEventWireup="false" Inherits="TestCenter.FileUp" %>
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transisi//EN" >
3<HTML>
4 <KEPALA>
5 <judul>多文件上传</title>
6 <bahasa skrip="JavaScript">
7 fungsi tambahkanFile()
8 {
9 var str = '<INPUT type="file" size="50" NAME="File">'
10 dokumen.getElementById('File Saya').insertAdjacentHTML("beforeEnd",str)
11 }
12 </skrip>
13 </KEPALA>
14 <tubuh>
15 <form id="form1" method="post" runat="server" enctype="multipart/form-data">
16 <div align="tengah">
17 <h3>多文件上传</h3>
18 <P id="File Saya"><INPUT type="file" size="50" NAME="File"></P>
19 <P>
20 <input type="button" value="增加(Tambahkan)" onclick="addFile()">
21 <input onclick="this.form.reset()" type="button" value="重置(Reset)">
22 <asp:Button Runat="server" Text="开始上传" ID="UploadButton"></asp:Button>
23 </P>
24 <P>
25 <asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt"
26 Lebar="500px" BorderStyle="Tidak Ada" BorderColor="Putih"></asp:Label>
27</P>
28 </div>
29 </bentuk>
30 </tubuh>
31</HTML>
32
//****************************************************** ****************
//////FileUp.aspx.cs
1menggunakan Sistem;
2menggunakan System.Collections;
3menggunakan System.ComponentModel;
4menggunakan Sistem.Data;
5menggunakan System.Drawing;
6menggunakan Sistem.Web;
7menggunakan System.Web.SessionState;
8menggunakan Sistem.Web.UI;
9menggunakan System.Web.UI.WebControls;
10menggunakan System.Web.UI.HtmlControls;
11
12Pusat Tes namespace
13{
14 /**//// <ringkasan>
15 /// 实现多文件上传
16 /// </ringkasan>
17 FileUp kelas publik: System.Web.UI.Page
18 {
19 System.Web.UI.WebControls.Button UploadButton yang dilindungi;
20 Sistem.Web.UI.WebControls.Label strStatus yang dilindungi;
21
22 private void Page_Load(pengirim objek, System.EventArgs e)
23 {
24 jika (ini.IsPostBack) ini.SaveImages();
25 }
26
27 Boolean SaveImages pribadi()
28 {
29 /**////'遍历File表单元素
30 File HttpFileCollection = HttpContext.Current.Request.Files;
31
32 /**//// '状态信息
33 System.Text.StringBuilder strMsg = Sistem.Teks.StringBuilder() baru;
34 strMsg.Append("上传的文件分别是:<hr color=red>");
35 mencoba
36 {
37 untuk(int iFile = 0; iFile < files.Count; iFile++)
38 {
39 /**////'检查文件扩展名字
40 HttpPostedFile dipostingFile = file[iFile];
41 string Nama file, Ekstensi file;
42 namafile = System.IO.Path.GetFileName(postedFile.FileName);
43 jika (Namafile != "")
44 {
45 fileExtension = System.IO.Path.GetExtension(namafile);
46 strMsg.Append("上传的文件类型:" + dipostingFile.ContentType.ToString() + "<br>");
47 strMsg.Append("客户端文件地址:" + dipostingFile.NamaFile + "<br>");
48 strMsg.Append("上传文件的文件名:" + Namafile + "<br>");
49 strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
50 /**////'可根据扩展名字的不同保存到不同的文件夹
51 ///注意:可能要修改你的文件夹的匿名写入权限。
52 dipostingFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + nama file);
53 }
54 }
55 strStatus.Teks = strMsg.ToString();
56 mengembalikan nilai benar;
57 }
58 tangkapan(Sistem.Pengecualian Ex)
59 {
60 strStatus.Teks = Contoh.Pesan;
61 mengembalikan salah;
62 }
63 }
64