获取上传的文件

时间:2014-09-07 13:08:11

标签: c# asp.net ckfinder

如何获取所有上传文件的列表?我想在下拉列表中列出文件,以便用户可以从列出的下拉列表中选择要解压缩的文件。 我有以下代码:

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);

}

1 个答案:

答案 0 :(得分:0)

这是您获取目录列表的方式:

<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对象的帮助下回发并下载文件。

  Response.ContentType = "application/<type of file>";
    Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName ));
...