This is my code when saving the document to a stream:
- Code: Select all
using (MemoryStream stream = new MemoryStream())
{
stream.Position = 0;
document.SaveToStream(stream, FileFormat.Docx);
return stream.ToArray();
}
This is the code in my controller (content is the stream.ToArray() returned from the previous code):
- Code: Select all
[HttpGet("/api/fileBuilder/exportWordFileChemicalAnalysisRequest")]
public async Task<FileContentResult> ExportWordFileChemicalAnalysisRequest()
{
var content = await Mediator.Send(new ExportWordFileChemicalAnalysisRequestQuery());
var contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
var fileName = "exampleWord";
return File(content, contentType, System.Web.HttpUtility.UrlEncode(fileName));
}
This is the code in vue.js:
- Code: Select all
downloadWordFile() {
this.$http.get("/api/fileBuilder/exportWordFileChemicalAnalysisRequest")
.then(resp => {
console.dir(resp);
return {
blob: new Blob([resp.data], { type: resp.headers['content-type'] }),
filename: resp.headers['content-disposition']
};
})
.then(data => {
const url = window.URL.createObjectURL(data.blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// the filename you want
a.download = decodeURI(data.filename.split(';')[1].trim().split('=')[1]);
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch((error) => {
console.log("Грешка при свалянето на данните!");
console.log(error);
});
}
Please help me, I have searched but could not find a solution to my problem.