Aspose Word Doc conversion corrupts

Hi

I’m trying to convert a Word (DOC) to Word (DOCX) sending in a memory stream from a FileStream
and I want to return a stream to save in sharepoint

 private static MemoryStream ConvertWordDocument(Stream ms)
        {
            try
            {
                var docStream = ConvertStreamToMemoryStream(ms);
                docStream.Position = 0;
                var doc = new Document(docStream);
                var saveOptions = Aspose.Words.SaveFormat.Docx;
                doc.Save(docStream, saveOptions);
                docStream.Position = 0;

                return docStream;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return null;
            }
        }

Everytime I do so the file ends up corrupt.
Thanks, Mikey

@mikesoffice,

Please ZIP and upload your input and output Word documents (.doc/.docx files) here for testing. We will investigate the issue on our end and provide you more information.

Aspose.zip (8.7 KB)

@mikesoffice,

Thanks for your inquiry. After an initial test with the latest version of Aspose.Words for .NET i.e. 18.2, we were unable to reproduce this issue on our end.

In case the problem still remains, please create a standalone runnable simple console application (source code without compilation errors) that helps us reproduce your problem on our end, ZIP it and attach the ZIP file here for further testing.

I find this difficult to reproduce the code in a small application as the input stream is being passed from a http input base stream which is convert to a memory stream to be converted to a stream to be save in sharepoint CheckEmailFormat.zip (4.0 KB)

Please find attached all the relevant classess

@mikesoffice,

It is difficult to say what the problem is; because we are unable to reproduce this issue on our end by using the following simple code:

private static MemoryStream ConvertWordDocument(MemoryStream ms, SaveFormat saveFormat)
{
    if (!CheckWordFormat.Run(sm)) return null;

    try
    {
        var doc = new Document(ms);
        var saveOptions = saveFormat;

        MemoryStream outputMs = new MemoryStream();
        doc.Save(outputMs, saveOptions);
        outputMs.Position = 0;

        return outputMs;
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
        return null;
    }
}
///////////////
MemoryStream stream = new MemoryStream(File.ReadAllBytes(MyDir + @"Aspose\Aspose.docx"));
MemoryStream ms = ConvertWordDocument(stream, SaveFormat.Docx);
Document doc = new Document(ms);
doc.Save(MyDir + @"Aspose\18.2.docx");

Hi

I do not want to sav to disk at this point but pass teh meoery stream back to sharepoint and save in that given location

@mikesoffice,

You can save the document to memory stream by using the following code:

MemoryStream stream = new MemoryStream(File.ReadAllBytes(MyDir + @"Aspose\Aspose.docx"));
MemoryStream ms = ConvertWordDocument(stream, SaveFormat.Docx);
Document doc = new Document(ms);
MemoryStream outMS = new MemoryStream();
doc.Save(outMS, SaveFormat.Docx);

The content of outMS stream can be saved to SharePoint for future use.

Hi

I’m afraid it does not work as when I try to open the document I get this error message
WordErrorMsg.png (4.9 KB)

Where is this function ConvertWordDocument(stream, SaveFormat.Docx);???

Found It thank you

Even when I call my own function it still does not work I still get the same error message

I want to save this stream to sharepoint not to disk hence the reason for the conversion.
Sorry to say we do not seem to be getting very far with this product and having spent the huge some of money on a license finding the product not coming up to scratch. As for support giving me the same answer - unable to reproduce doesn’t go down well.

Is there anyone that can help?

@mikesoffice,

Please also ZIP and attach Aspose.Words generated output document that shows this error in Word Online.

You have only attached this input.zip (8.7 KB) as your input Word document. We have generated this output.zip (8.3 KB) by using this code and are unable to see any problems in Word Online .

I think, instead of using existing MemoryStream, you should create a new MemoryStream object and save it to SharePoint.

MemoryStream forSP = new MemoryStream(outMS.ToArray());

Hope, this helps.

Hi

Here is my sharepoint code

using (var stream = new MemoryStream(document))
{
    File.SaveBinaryDirect(context.ClientContextInstance, $"{folder.ServerRelativeUrl}/{fileCreationInformation.Url}", stream, false);
}

As you can see I’m already doing what you suggested. Still saves a corrupt Word, Excel, Email, Powerpoint

The problem is, in my mind, clearly with your product not generating the correct format of file content.

Thanks, Mike

PS How much is the paid support maybe they can help shine a light on the problem and resolve?

@mikesoffice,

I have observed your comments. Please share source file and generated result regarding Aspose.Slides issue so that we can help you out or post a query in Aspose.Slides forum regarding PowerPoint issues.

Hi
I have resolved the issue this morning, than you.
thanks Mike