private readonly IHostingEnvironment _hostingEnvironment;
public ExcelController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[HttpGet("GetFile")]
public IActionResult GetFile()
{
string url = $"{Request.Scheme}://{Request.Host}{Request.PathBase}/file/";
string path = _hostingEnvironment.ContentRootPath + @"\file\";
try
{
DirectoryInfo dir = new DirectoryInfo(path);
FileInfo[] finfo = dir.GetFiles();
string fnames = string.Empty;
List<ExcelModel> ms = new List<ExcelModel>();
for (int i = 0; i < finfo.Length; i++)
{
string weburl = url + finfo[i].Name;
string fileurl= path + finfo[i].Name;
ExcelModel m = new ExcelModel();
m.filename= finfo[i].Name;
m.intime = finfo[i].CreationTime;
//var stream = System.IO.File.OpenRead(fileurl);
//m.stream= File(stream, "application/vnd.android.package-archive", Path.GetFileName(fileurl));
m.url = weburl;
ms.Add(m);
}
var response = new
{
code = 20000,
data = ms
};
return Ok(response);
}
catch (Exception)
{
throw;
}
}