im currently working on a project that intend to download attachment posted to the Server DB on the client system using the file path stored in the server DB on Windows form. im stucked and need help. thanks
Loading
im currently working on a project that intend to download attachment posted to the Server DB on the client system using the file path stored in the server DB on Windows form. im stucked and need help. thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aman GuptaRank #193 · 12.4K reputationPosted Jul 17, 2021, 11:54 AM EDT
Here's one possible solution to your problemNote: I haven't tested this code so it might need some little tweaks.
public ActionResult ExportFile(string[] years, string[] months, string[] radio, string[] acctNum) {Statement theStatementPath = new Statement();var thePath = theStatementPath.statementPath;List allPaths = new List();if (years != null){using (var db = new dbentities()){// we will store the contents of the zip file in memory, // just be careful if you have too many files you might run out of memoryusing (var memoryStream = new MemoryStream()){// create a zip archive and pass the memory as a parameter// you dont need a path, cause as like I said the zip will be in memoryusing (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)){foreach (var aYear in years){List paths = db.Statement.Where(x => x.statementYear == aYear).Select(y => y.statementPath).ToList();// iterate all the paths for a given yearforeach (var path in paths){// check if the file at the path existsif (File.Exists(path)){// load the file into the zip archivezip.CreateEntryFromFile(path, path);}}}// once you iterate all years, return the zip file to browserreturn File(zip, "application/zip", "pdfs.zip");}}}} }hope this helps
Sulaiman Kukoyi15 reputationPosted Jul 22, 2021, 2:24 AM EDT