none
word document customization and Arithmetic operation resulted in an overflow RRS feed

  • Question

  • I have created a very simple document level customization for the Word 2007:

    public partial class ThisDocument
        {
            [Cached()]
            public string q;
    
            private void ThisDocument_Startup(object sender, System.EventArgs e)
            {
                txtTest.Text = q;
            }
        }

    and I published it on the IIS. Now from the ASP.NET page:

    protected void Page_Load(object sender, EventArgs e)
            {
                FileStream fs = new FileStream(
    @"C:\inetpub\www\WordDocument.docx", FileMode.Open, FileAccess.Read);
    
                byte[] template;
                try
                {
                    template = new byte[fs.Length];
                    fs.Read(template, 0, (int)fs.Length);
                }
                finally
                {
                    fs.Close();
                }
    
                try
                {
                    ServerDocument sd = new ServerDocument(template, ".DOCX");
                    sd.CachedData.HostItems[0].CachedData[0].SerializeDataInstance("test");
                    sd.Save();
                    template = sd.Document;
                }
                catch (Exception)
                {
                }
    
                Response.ClearContent();
                Response.ClearHeaders();
                Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                Response.OutputStream.Write(template, 0, template.Length);
                Response.Flush();
                Response.Close();
            }

    This works properly. But now I want to create a *.doc, not *.docx file and I have a problem. I replaced the template file, and in the ServerDocument when I changed the file type to DOC, I get from this ServerDocument exception: Arithmetic operation resulted in an overflow. This looks like a problem with the x86/x64 target type? When I changet it to x86 (for the ASP.NET page) a got another exception: BadImageFormatException. Can someone show some workaround/fix for it? And second. If this will work, is this possible to launach that doc file on a system, where is only a version of Word <= 2003?

    Monday, June 18, 2012 5:25 PM

Answers

  • Hello Lszi86,

    The BadImageFormatException message appears to reflect a difference between 32-bit and 64-bit systems where the expectation is the presence of a 32-bit dll but the expected module is appropriate to the 64-bit server. Is there any more information in the error message? Please share it with us. Also, use the entire error message as a string as a query in bing or google.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Thursday, June 21, 2012 8:21 PM
    Moderator

All replies

  • Hi Lszk86,

    Thank you for posting in the MSDN Forum.

    I'll involve some experts who are familiar with your issue, this may take some time.
    Much appreciate for your patient and understanding.

    Best regards,
    Quist

    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 19, 2012 2:53 PM
    Moderator
  • Hello Lszi86,

    The BadImageFormatException message appears to reflect a difference between 32-bit and 64-bit systems where the expectation is the presence of a 32-bit dll but the expected module is appropriate to the 64-bit server. Is there any more information in the error message? Please share it with us. Also, use the entire error message as a string as a query in bing or google.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Thursday, June 21, 2012 8:21 PM
    Moderator