Код: Выделить всё
public FileContentResult GetDocument(String pathName)
{
try
{
Byte[] buffer = BlobStorage.DownloadFile(pathName);
FileContentResult result = new FileContentResult(buffer, "PDF");
String[] folders = pathName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
// get the last one as actual "file name" based on some convention
result.FileDownloadName = folders[folders.Length - 1];
return result;
}
catch (Exception ex)
{
// log error
}
// how to handle if file is not found?
return new FileContentResult(new byte[] { }, "PDF");
}
Мой вопрос указан в комментарии к коду: Как мне справиться со сценарием, когда файл/поток не найден? В настоящее время я передаю пустой PDF-файл, что, по моему мнению, не лучший способ сделать это.
Подробнее здесь: https://stackoverflow.com/questions/645 ... -not-found