Word Document opening with an exceptionally huge(unwanted) width !! RRS feed

  • Question

  • Hi,

    I have a code that downloads a file by calling a web service and opens that file in a word document.But,after the file gets opened in the word doc,the width of the word doc becomes exceptionally long,although,the file downloaded wasn't that huge.So,i end up getting so much  unused white space on the right hand side of the doc.
    PFB the code used for opening the downloaded file in word doc.

    string tempdir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                string tempfile = Path.Combine(tempdir, documentName);
                System.IO.File.WriteAllBytes(tempfile, content);
                object missing = System.Reflection.Missing.Value;
                object fileName = tempfile;
                object readOnly = true;
                object isVisible = true;
                object confirmConversions = true;
                object addToRecentFiles = false;
                    ref fileName,
                    ref confirmConversions,
                    ref readOnly,
                    ref addToRecentFiles,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref isVisible,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing);

    I tried to fix the issue by setting the RightMargin to 0(zero),But,that didn't help.

    ThisAddIn.Application.ActiveDocument.ActiveWindow.Document.PageSetup.RightMargin = 0;

    Please share,if anyone has any idea about what's going wrong here.
    Tuesday, January 7, 2014 1:30 PM

All replies

  • Hi Paul

    What kind of file is this, originally (what's the file extension)?

    Which version of Word are you using (so that we can give you command names that make sense in your context)?

    My first thought is that there's a carriage return/new line at the end of every line of text which is forcing the text to break. If you turn on the display of non-printing characters you'd be seeing a "backwards P" at the end of every line. (Options/Display/Paragraph marks needs to be activated in the version of Word I use.)

    If this is what you see, then you need to remove these so that the text can wrap to the width of the document. Generally, I'd use Word's Rangel.Find, with Replace, to do that if I need to retain formatting.

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, January 8, 2014 9:16 AM