My requirement is to open a file in a new window/tab upon clicking the download link. The file is always downloaded despite setting the content disposition to 'inline' as suggested in the below post.
How to open PDF file in a new tab or window instead of downloading it (using asp.net)?
My HTTP response is
HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
public async Task<FileContentResult> Index(string fileName)
byte document = await getFileContent("SomePathForTheFile");
HttpContext.Response.AddHeader("content-disposition", "inline;filename=" + document.FileName);
return File(document, "application/octet-stream");
Found the answer.
2 things have to be done for the file to open in a new window -
1.content-disposition must be set to inline
2.the content type should be set to the type corresponding to the file being downloaded -
application/pdf - for pdf files
application/xml - for xml files
application/vnd.ms-excel - for xls files and so on.