Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri May 22, 2020 8:22 am

Hello, I have a problem when saving a docx document to a stream. After sending the file to the front-end and then I download the file, the document can not be opened and MS Word alert me with this message: We`re sorry. We can`t open exampleWord.docx because we found a problem with its content.
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.

MartoK96
 
Posts: 1
Joined: Fri May 22, 2020 8:11 am

Fri May 22, 2020 9:35 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more accurately and quickly, please provide your input file along with your output file for reference. You could upload them here or send them to us(support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Jun 17, 2020 3:32 am

Hello,

Greetings from E-iceblue.
Has your issue been resolved? If it still bothers you, please provide more information to help us investigate further.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc

cron