我想下载一个文件夹,其文件为各种MIME类型。我的虚拟路径是“http://localhost/attachments/”。我的子文件夹是“证书/ ID”。所以当点击一个网格时,我会将id传递给下载页面。但它会抛出一个像虚拟路径的异常无效。 'http://localhost/attachments/certificates/id)'。如何使用asp.net C从服务器下载包含文件的文件夹#
在下面的代码中,Request.Params [0]意味着id,这指向了我想创建zip文件夹的endlevel文件夹。
任何指导将不胜感激。
using (ZipFile zip = new ZipFile())
{
string VirtualPath = ConfigurationManager.AppSettings.Get("AttachmentsShowVirtualPath");
string Path = string.Empty;
Path = "certificates" + "/";
string folderPath = VirtualPath + Path + Request.Params[0] + "/";
zip.CompressionLevel = CompressionLevel.None;
zip.AddSelectedFiles(".", Server.MapPath(folderPath), "", false);
zip.Save(Response.OutputStream);
}
您是否检查过您的folderPath字符串是否正确?你在哪一行得到异常? – user3378165
在这一行它会抛出异常,虚拟路径无效。 zip.AddSelectedFiles(“。”,Server.MapPath(folderPath),“”,false);但我指出的文件夹路径是正确的。 –