public HttpResponseMessage DownloadFile(string fileName) { HttpResponseMessage response = Request.CreateResponse(); try { string filePath = string.Concat(this.GetDownloadPath(), "\\", fileName); FileInfo fileInfo = new FileInfo(filePath); FileMetaData metaData = new FileMetaData(); if (!fileInfo.Exists) { metaData.FileResponseMessage.IsExists = false; metaData.FileResponseMessage.Content = string.Format("{0} file is not found !", fileName); response = Request.CreateResponse(HttpStatusCode.NotFound, metaData, new MediaTypeHeaderValue("text/json")); } else { response.Headers.AcceptRanges.Add("bytes"); response.StatusCode = HttpStatusCode.OK; response.Content = new StreamContent(fileInfo.ReadStream()) { Headers = {ContentType = new MediaTypeHeaderValue("application/octet-stream")} }; response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; response.Content.Headers.ContentLength = fileInfo.Length; } } catch (Exception exception) { response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception); } return response; }