Aspose.Words Docx document truncated at 20kB after/during download

Dear,
I’ve encounterd a problem with following code.
When a .doc file - generated/updated by Aspose.Words - is downloaded, the complete file is received, and works fine (local and online). However, when a docx file - generated/updated by Aspose.Words - is downloaded, only 20kB (no matter how big it is) is downloaded, and Word2007 says that the document is corrupted when opening.
Extra problem is that testing this offline (Windows Vista, Visual Studio 2005 in debug or local IIS 6.0), this error does not occur. Online (same IIS 6.0, operating system Windows 2003), we have the problem.
I use following code:

string FILE_NAME = (string)fileRef["name"];
string docExtension = FILE_NAME.Substring(fileAndPath.LastIndexOf('.') + 1);
...
// Open template
Document doc = new Document(fileAndPath);
...

if (docExtension.ToLower() == "docx")
doc.Save(FILE_NAME, SaveFormat.Docx, Aspose.Words.SaveType.OpenInWord, Response);
else if (docExtension.ToLower() == "doc")
doc.Save(FILE_NAME, SaveFormat.Doc, Aspose.Words.SaveType.OpenInWord, Response); 
Response.End();

We also tried following code, and displayed the wordstream legth after the doc.save, to verify whether it was due to the transfer. The length displayed was also 20kB, which means that Aspose.Words seems to truncate the document.

MemoryStream wordStream = new MemoryStream(); 
...
if (docExtension.ToLower() == "docx")
doc.Save(wordStream, SaveFormat.Docx);
else if (docExtension.ToLower() == "doc")
doc.Save(wordStream, SaveFormat.Doc); wordStream.Flush();
int wordStreamLength = (int)wordStream.Length;
wordStream.Close(); 
if (wordStream != null)
{
Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); 
byte[] bytes = wordStream.GetBuffer();
Response.OutputStream.Write(bytes, 0, wordStreamLength);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.End();
}

Are there settings which might be different on my local system in comparison to the server?
Thanks for your help.

This message was posted using Aspose.Live 2 Forum

Hi

Thanks for your inquiry. Could you please create simple application, which will demonstrate the problem on my side? I will check your code and provide you more information.
Best regards,

Hi,
we made a little aspx app which also encounters the error. Actually, the truncation we encountered before is due to embedded Excel objects, so this isn’t an error. However when Word2007 opens the docx file, it still gives the “corrupt” message.
We get the error when using directly the Response in the save, and when we use the memorystream.
Not working with stream: WordsText.aspx.cs (attached in CsFiles.zip)
link: www.flexisle.net/WordsText.aspx
Not working with Response in save: WordsText2.aspx.cs (attached in CsFiles.zip)
link: www.flexisle.net/WordsText2.aspx
The original document is also attached (Big.docx).

Hi

Thank you for additional information. I tested this on Windows XP (IIS6) and on Windows 2003 (IIS7) and all works fine on my side. The output DOCX document is not truncated an can be successfully opened in MS Word.
Best regards.

Hi,
you mentioned testing it on IIS6 and IIS7, which I suppose you mean that you tested it locally on your system?
Locally, this also works at our site. Problem is that when using this online, we receive the errors. After showing the error, Word2007 asks whether we trust the document and would like for Word2007 to repair the document. When you click ‘ok’, we receive the document completely. So, the document is not changed, but we keep getting the first error message.
This is a problem which occurs at all our different sites, meaning that this is not only at the development center here.

When downloading the document by one of the links in my previous message, don’t you get the error message?

Could you please look into this?

Thanks in advance.

Hi

Thank you for additional information. When I tried the links a hour ago, they did not work. Now, I can download files from these links. I can confirm that the documents downloaded from the links are corrupted.
But, I also found that you use old version of Aspose.Words (7.0.0). If I just open save the document downloaded from one of your links using the latest version of Aspose.Words, MS Word can successfully open it.
Probably the problem does not occur in your developer environment because you use the latest version for testing, but use the older one on your server. Could you please try using the latest version? You can download it from here:
https://releases.aspose.com/words/net
Best regards.

Hi,
thanks for your fast response (what’s the time in Auckland ?? :slight_smile: )
we loaded the new version (8.0.0.0.), and retried the test for both links. We still encounter the same problem: message that the document is damaged.
We also checked the words version in the downloaded doc in the document.xml file (), which is correct.

The version I used locally, actually is the 7.0.0., and not the most recent version.

Your help would be much appreciated.
Thanks in advance.

Hi

Thank you for additional information. I looked at your document and found that there are some stack trace appended to the end of the document.

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        License license = new License();
        license.SetLicense("Aspose.Words.lic");
        string fileAndPath = @"D:\Bestanden\Big.docx";
        FileInfo fi = new FileInfo(fileAndPath);
        Document doc = new Document(fi.FullName);
        doc.Save(fi.Name, SaveFormat.Docx, SaveType.OpenInApplication, Response);
        Response.End();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message + "" + ex.StackTrace.Replace("\n", ""));
        Response.End();
    }
}

It seems the highlighted code causes the problem. Could you please try removing this code and let me know how it goes on your side.
Best regards.

Hi,
your tip helped us. We detected that the Response.End() was called twice. Removing the second one solved the problem.
Thanks for your input (and patience).
Have a nice weekend !