public IActionResult GetKeys(int customerSettingsid) { try { var _customerSettings = _repository.Get() .Include(c => c.Customer) .Include(p => p.Product) .Where(x => x.CustomersProductsId == customerSettingsid).First(); string filePathFull = Path.Combine(@"C:\Celta Business Solutions\" + _customerSettings.Customer.RootDirectory + @"\BSF\bin\ParChaves" + _customerSettings.Customer.RootDirectory + ".zip"); string path = Path.Combine(@"C:\Celta Business Solutions\" + _customerSettings.Customer.RootDirectory + @"\BSF\bin\ParChaves" + _customerSettings.Customer.RootDirectory + ".zip"); if (SystemFilesHelper.FileExist(filePathFull)) { string _path = Path.Combine(@"C:\Celta Business Solutions\" + _customerSettings.Customer.RootDirectory + @"\BSF\bin\"); IFileProvider provider = new PhysicalFileProvider(_path); IFileInfo fileInfo = provider.GetFileInfo("ParChaves" + _customerSettings.Customer.RootDirectory + ".zip"); var readStream = fileInfo.CreateReadStream(); return(File(readStream, "application/x-zip", "ParChaves" + _customerSettings.Customer.RootDirectory + ".zip")); } else { if (SystemFilesHelper.CompressFileOrFolder(@"C:\Celta Business Solutions\" + _customerSettings.Customer.RootDirectory + @"\BSF\bin\", _customerSettings.Customer.RootDirectory)) { //baixar o arquivo então string _path = Path.Combine(@"C:\Celta Business Solutions\" + _customerSettings.Customer.RootDirectory + @"\BSF\bin\"); IFileProvider provider = new PhysicalFileProvider(_path); IFileInfo fileInfo = provider.GetFileInfo("ParChaves" + _customerSettings.Customer.RootDirectory + ".zip"); var readStream = fileInfo.CreateReadStream(); return(File(readStream, "application/x-zip", "ParChaves" + _customerSettings.Customer.RootDirectory + ".zip")); } else { return(NotFound("Ocorreu um erro na criação do arquivo compactado.")); } } } catch (Exception err) { return(NotFound(err.Message)); } }
public IActionResult GetCertificateFile(int id) { var certificate = _repository.Get() .Include(c => c.Customer). Where(x => x.CertificateId == id). First(); string path = $"C:\\Celta Business Solutions\\{certificate.Customer.RootDirectory}\\BSF\\certificados\\{certificate.FileRepositorie}\\"; string filePathFull = Path.Combine(path, certificate.FileName); if (SystemFilesHelper.FileExist(filePathFull)) { IFileProvider provider = new PhysicalFileProvider(path); IFileInfo fileInfo = provider.GetFileInfo(certificate.FileName); var readStream = fileInfo.CreateReadStream(); // "application/octet-stream" return(File(readStream, "application/octet-stream", certificate.FileName)); } return(NotFound("arquivo não encontrado")); }