這是一個(gè)獲取文件夾文件的信息
public static List<Filters> GetFileList(string path1)
{ DirectoryInfo d = new DirectoryInfo(path1); FileInfo [] fl= d.GetFiles(); List<Filters> lis = new List<Filters>(); foreach(FileInfo f in fl ) { Filters fi = new Filters(); fi.Extends = f.Extension; fi.Fullname = f.FullName; fi.Length = f.Length; fi.Name = f.Name; lis.Add(fi); } return lis; } 下面是文件的aspx
<body>
<form id="form1" runat="server"> <div> <div> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <asp:Button ID="btnupload" runat="server" Text="文件上傳" onclick="btnupload_Click" /> <asp:Label ID="lblManager" runat="server" Text="Label"></asp:Label> </div> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="name" HeaderText="文件名稱" /> <asp:BoundField DataField="extends" HeaderText="文件后綴名稱" /> <asp:BoundField DataField="length" HeaderText="文件大小" /> <asp:TemplateField HeaderText="下載"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("Fullname") %>' oncommand="LinkButton1_Command">LinkButton</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </div> </form> </body> 下面是文件的aspx.cs
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{ Response.Clear();
string path = e.CommandArgument.ToString(); Response.AddHeader("Content-disposition", "Attachment;filename=" + HttpUtility.UrlEncode(path)); Response.WriteFile(path); Response.End(); } |
|