HEGDE HEGDE - 4 months ago 40
C# Question

Download ZIP file From path stored in Database MVC C#

Need to download zip file content, path is stored in sqlserver, i am using FILERESULT Action method in controller.
My Controller looks like this:

public FileResult Download(string id)
{
string txtvalue = null; int cat = 0;

string searchType = Session["type"].ToString();
if (searchType == "name")
{
txtvalue = Session["item"].ToString();
}
else if (searchType == "cat")
{
cat = Convert.ToInt32(Session["item"]);
}
int fid =Convert.ToInt32(Session["Fid"]);
var files = _urepo.GetprojectName(fid);
string filename = (from f in files
select f.PRJ_LOCATION).SingleOrDefault();
string contentType = "application/zip";

return File(filename, contentType,"download"+filename);
}


But only file is downloading...contents are not downloading..
any help will be apprciated

Answer

I Got It, Actually As CodeCaster Said, Contents were Missing While Archiving. Later I appended data With Ajax Call.

public FileResult Download()
        {
            int Id = Convert.ToInt32(TempData["FileID"]);

            var files = _urepo.GetprojectName(Id);
            string filename = (from f in files
                               select f.PRJ_LOCATION).SingleOrDefault();
            string contentType = "application/zip";
           byte[] fileBytes = System.IO.File.ReadAllBytes(filename);

            string file=filename.Substring(filename.LastIndexOf("\\")+1);
             return File(fileBytes, contentType, file);
        }

Thank You All.

Comments