获取上传的文件
本文关键字:文件 获取 | 更新日期: 2023-09-27 18:20:53
如何获取所有上传文件的列表?我想在下拉列表中列出文件,这样用户就可以从列出的下拉列表中选择要解压缩的文件。我有以下代码:
var path = Server.MapPath(Project.DataDirectoryPath);
string valueShownInDropDownList = dropDown.selectedValue+".zip"; (The value of uploaded file should be shown here)
var targetToExtract = string.format("{0}/FileBrowser/TestProj/files,projectPath");
using (ZipFile z = ZipFile.Read(targetToExtract.toString())))
{
entry. Extract(targetToExtract);
}
这就是您获得目录列表的方式:
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server">
<asp:ListItem Text="--Select Files--" Value="0" />
</asp:DropDownList>
服务器端:
var exDir = @"c:'temp'directory";
DirectoryInfo dir = new DirectoryInfo(exDir);
foreach (FileInfo exFile in dir.GetFiles())
{
ListItem lst = new ListItem ( xFile.FullName , "0" );
DropDownList1.Items.Insert( DropDownList1.Items.Count-1 ,lst);
}
在选择任何文件时,您应该在响应对象的帮助下发布并下载文件。
Response.ContentType = "application/<type of file>";
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName ));
...