public HttpResponseMessage GetDocument(int goodId, int docId) { var document = _service.GetDocument(goodId, docId); var documentfile = _service.GetDocumentBytes(goodId, docId); if (document == null || documentfile == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } const HttpStatusCode statuscode = HttpStatusCode.OK; var response = Request.CreateResponse(statuscode); response.Content = new StreamContent(new System.IO.MemoryStream(documentfile)); response.Content.Headers.ContentLength = documentfile.Length; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = document.Name }; response.Content.Headers.ContentDisposition.FileName = document.Name; response.Content.Headers.ContentLength = documentfile.Length; response.Headers.Add("fileName", document.Name); return(response); }