[英]Downloading csv files with zip?
我有此代码,问题是,每当我按下下载按钮时,都会出现错误,指示未找到目录。 我已经具有以下fileUpload.PostedFile.SaveAs(Server.MapPath("~/Upload"));
的上传功能fileUpload.PostedFile.SaveAs(Server.MapPath("~/Upload"));
下面是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var files = Directory.GetFiles(@"~/Upload");
gvFiles.DataSource = from f in files
select new
{
FileName = Path.GetFileName(f)
};
gvFiles.DataBind();
}
}
protected void btnDownload_Click(object sender, EventArgs e)
{
string fileName = string.Empty;
string filepath = Request.MapPath("~/Upload");
string downloadFileName = "Attendance.zip";
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + downloadFileName);
using (ZipFile zip = new ZipFile())
{
foreach (GridView row in gvFiles.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
if (cb != null && cb.Checked)
{
fileName = (row.FindControl("lblFileName") as Label).Text;
zip.AddFile(Server.MapPath(Path.Combine(filepath, fileName)), "");
}
}
zip.Save(Response.OutputStream);
}
}
有人可以帮我吗? 当我使用Directory.GetFiles(@“〜/ Upload”)时,出现上述错误
Directory.GetFiles需要一个现有的本地路径,死了〜语法在这里是不可能的。 之前使用
MapPath
:
var files = Directory.GetFiles(Request.MapPath("~/Upload"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.