diff --git a/ADefHelpDeskWebApp/Components/Pages/TicketControls/TicketEditDetailControl.razor b/ADefHelpDeskWebApp/Components/Pages/TicketControls/TicketEditDetailControl.razor index 4f369e1..502e54d 100644 --- a/ADefHelpDeskWebApp/Components/Pages/TicketControls/TicketEditDetailControl.razor +++ b/ADefHelpDeskWebApp/Components/Pages/TicketControls/TicketEditDetailControl.razor @@ -239,34 +239,43 @@ private async void DownloadAttachment(DTOAttachment paramAttachment) { - showWaitAttachmentGraphic = true; - StateHasChanged(); + try + { + showWaitAttachmentGraphic = true; + StateHasChanged(); - var url = new Uri($"{NavigationManager.BaseUri}api/Files/ReturnFile"); + var url = new Uri($"{NavigationManager.BaseUri}api/Files/ReturnFile"); - var request = new DTOFileParameter(); - request.attachmentID = paramAttachment.attachmentID; - request.emailFileName = paramAttachment.fileName; - request.detailId = SelectedTaskDetail.detailId; - request.portalId = -1; - request.taskId = SelectedTask.taskId ?? -1; - request.ticketPassword = SelectedTask.ticketPassword; + var request = new DTOFileParameter(); + request.attachmentID = paramAttachment.attachmentID; + request.emailFileName = paramAttachment.fileName; + request.detailId = SelectedTaskDetail.detailId; + request.portalId = -1; + request.taskId = SelectedTask.taskId ?? -1; + request.ticketPassword = SelectedTask.ticketPassword; - var myContent = JsonConvert.SerializeObject(request); - var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); - var byteContent = new ByteArrayContent(buffer); - byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); + var myContent = JsonConvert.SerializeObject(request); + var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); + var byteContent = new ByteArrayContent(buffer); + byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); - var response = await client.PostAsync(url, byteContent); - var fileName = response.Content.Headers.ContentDisposition.FileNameStar; + var response = await client.PostAsync(url, byteContent); + var fileName = response.Content.Headers.ContentDisposition.FileNameStar; - showWaitAttachmentGraphic = false; - StateHasChanged(); + showWaitAttachmentGraphic = false; + StateHasChanged(); - using (var stream = await response.Content.ReadAsStreamAsync()) + using (var stream = await response.Content.ReadAsStreamAsync()) + { + using var streamRef = new DotNetStreamReference(stream: stream); + await JSRuntime.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef); + } + } + catch (Exception ex) { - using var streamRef = new DotNetStreamReference(stream: stream); - await JSRuntime.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef); + Message = ex.GetBaseException().Message; + showWaitAttachmentGraphic = false; + StateHasChanged(); } } diff --git a/ADefHelpDeskWebApp/Controllers/ExternalApi/FilesController.cs b/ADefHelpDeskWebApp/Controllers/ExternalApi/FilesController.cs index 0d32165..19bfe89 100644 --- a/ADefHelpDeskWebApp/Controllers/ExternalApi/FilesController.cs +++ b/ADefHelpDeskWebApp/Controllers/ExternalApi/FilesController.cs @@ -287,12 +287,19 @@ public static DTOFile ReturnFileMethod(DTOFileParameter paramDTOFileParameter, s } else { - // Get file contents - var fileContents = System.IO.File.ReadAllBytes(FullPath); + try + { + // Get file contents + var fileContents = System.IO.File.ReadAllBytes(FullPath); - objDTOFile.Buffer = fileContents; - objDTOFile.FileName = objAttachment.OriginalFileName; - return objDTOFile; + objDTOFile.Buffer = fileContents; + objDTOFile.FileName = objAttachment.OriginalFileName; + return objDTOFile; + } + catch (Exception ex) + { + throw new Exception("Get file contents:", ex); + } } } }