【发布时间】:2014-08-19 12:05:12
【问题描述】:
文件可以很容易地添加完整路径,例如:
z.Add(fpaths);
但我只想在下面添加文件而不是完整路径使用代码,但出现错误:
z.Add(fpaths, filenamed); error is! some invalid arguments
请查看我的代码,让我知道如何管理此代码
protected void btnAcceptAll_Click(object sender, EventArgs e)
{
int count = 0;
string msg = string.Empty;
string filenamezip = "FileFolder\\FilesZip.zip";
string strPathAndQuery = HttpContext.Current.Request.PhysicalApplicationPath;
string paths = strPathAndQuery + filenamezip;
ZipFile z = ZipFile.Create(paths);
z.BeginUpdate();
foreach (GridViewRow gvrow in gv.Rows)
{
CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
if (chk != null & chk.Checked)
{
count++;
string dirPath = gv.DataKeys[gvrow.RowIndex].Values[3].ToString();
string fileName = gv.DataKeys[gvrow.RowIndex].Values[1].ToString();
string filePath = dirPath + "/" + fileName;
string fpaths = strPathAndQuery + filePath;
string filenamed = Path.GetFileName(fpaths);
z.Add(fpaths, filenamed); //show error
}
}
if (count > 0)
{
z.CommitUpdate();
z.Close();
BindGrid();
Session["filenamezip"] = filenamezip;
ClientScript.RegisterStartupScript(GetType(), "SomeNameForThisScript", "window.open('DownloadZip.aspx', 'DownloadWindow','width=400,height=200');", true);
}
}
【问题讨论】:
标签: c# asp.net .net sharpziplib