Я сохранил файл Excel в папке на своем сервере, и я хочу загрузить его, когда пользователь нажимает кнопку в моем клиентском приложении.
Вот мое действие контроллера
public IActionResult BulkSample()
{
try
{
return File(
fileContents: ResourceFactory.GetEmbeddedResource("sample.xlsx"),
contentType: "application/vnd.ms-excel",
fileDownloadName: "sample.xlsx");
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
Вот код, который получает файл ниже resFilestream всегда null и возвращает null. Таким образом, мой файл не будет загружен.
что я здесь не так делаю?
public static class ResourceFactory
{
public byte[] GetEmbeddedResource(string name)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = $"Parent.Samples.{name}";
byte[] bytes;
using (Stream resFilestream = assembly.GetManifestResourceStream(resourceName))
{
if (resFilestream == null)
return null;
bytes = new byte[resFilestream.Length];
resFilestream.Read(bytes, 0, bytes.Length);
}
return bytes;
}
}