1

Hey Guys I am trying to set file download through Web api and angular, I ok when I know the Exact file type but what I don't know file type like some time I need to down load a .docx file and another time I need to download a .pdf file what exactly I need to do... I think i need to pass the File name with extension, I can't receive it from angular side..

here is my Api Method

public HttpResponseMessage GetStudentCase(studCaseReportModel studPreDetails)
    {

      ...
                result = new HttpResponseMessage(HttpStatusCode.OK);
                string fileName = studentcase.reportDocUrl;
      ...
                result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read));
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                result.Content.Headers.Add("x-filename", outFileName);
                result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                result.Content.Headers.ContentDisposition.FileName = outFileName;           

        return result;
    }

and here's my Angular code

$http.post(....).then(function (response) {
                var headers = response.headers();

                var filename = headers['x-filename'] || 'download.bin';
            },
}

and here's the result I get.... properties I got in header after callback... thanks for you help...

0 Answers0