【发布时间】:2018-03-20 10:20:49
【问题描述】:
我将 excel 文件存储在基于SYSDATE(当前日期)的文件夹中。现在我不想下载文件夹中的所有文件。
但我想从基于时间的文件夹中下载最新文件。这是我的代码的样子。目前我正在从 zip 文件夹中下载所有 excel 文件。
else if (strSelectedReportType == "RCOMReports")
{
string strReportFile = ConfigurationManager.AppSettings["RCOMReports"].ToString();
string strFilePath = ConfigurationManager.AppSettings["ReportDirectory"].ToString() + "\\" + DateTime.Now.ToString("dd-MM-yyyy");
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
if (Directory.Exists(strFilePath))
{
DirectoryInfo di = new DirectoryInfo(strFilePath);
FileInfo[] FileInfo = di.GetFiles();
if (FileInfo.Length > 0)
{
foreach (FileInfo item in FileInfo)
{
zip.AddFile(item.FullName, "Files");
}
}
MemoryStream ms = new MemoryStream();
Stream Objstream = new MemoryStream(ms.ToArray());
Objstream.Seek(0, SeekOrigin.Begin);
zip.AddEntry(strReportFile, Objstream);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BufferOutput = false;
string zipName = String.Format("Zip_{0}.zip", strReportFile);
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(HttpContext.Current.Response.OutputStream);
HttpContext.Current.Response.End();
}
else
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Alert", "alert('No Reports as on today's date..!!');", true);
}
}
}
现在我也不想要 Zip
【问题讨论】:
-
@nikhilmehta:谢谢 nikhil,我到了这里
myFile。现在我应该如何让它下载。 ?? -
@nikhilmehta:我在
FileInfo file = new FileInfo(myFile.Name);有文件名,但它在if (file.Exists)给我的结果是假的