Dim response As HttpResponseMessage = New HttpResponseMessage() ' _ms 是 MemoryStream, 這裡是因為要將NPOI所產生的excel檔做下載, 然而我將NPOI所產生出來的東西 ' 存入到 MemoryStream裡, 重點是ByteArrayContent Dim _filename as string = (filename) If _ms IsNot Nothing Then response.Content = New ByteArrayContent(_ms.ToArray()) End If response.Content.Headers.ContentType = New Headers.MediaTypeHeaderValue("application/octet-stream") response.Content.Headers.ContentDisposition = New Headers.ContentDispositionHeaderValue("attachment") With {.FileName = HttpUtility.UrlPathEncode(_filename)} Return Task.FromResult(response)