I have a function which zips files and downloads them to the users machine.
However, when it zips the files they are within a few folders.
For example if i want to zip a file called test.doc and it is in c:/document/the folder/test.doc
In the zipped folder there will be “document” folder and “the folder” too. I just want the document in there
here is my code…
public FileStreamResult DownloadDocs()
{
MemoryStream workStream = new MemoryStream();
ZipFile zip = new ZipFile();
string[] fileEntries = Directory.GetFiles(Server.MapPath(SettingManager.OnlineForms));
foreach (string fileName in fileEntries)
{
FileInfo fi = new FileInfo(fileName);
string name = Server.MapPath(SettingManager.OnlineForms + fi.Name);
zip.AddFile(name);
}
zip.Save(workStream);
workStream.Position = 0;
FileStreamResult fileResult = new FileStreamResult(workStream, System.Net.Mime.MediaTypeNames.Application.Zip);
fileResult.FileDownloadName = "OnlineForms.zip";
return fileResult;
}
Change the line
to
Also you could avoid the call to get the fileinfo. The array of file names should suffice.