none
How to read new line while reading doc file RRS feed

  • Question

  • Hi,

    I am trying to read a word file and dispplay its content in a label control.

    My code is below:

    private string ReadDOCFile(string p)
    {            
        Microsoft.Office.Interop.Word.Application msWord = new Application();
        object file = p;
        object obj_null = System.Reflection.Missing.Value;
        Microsoft.Office.Interop.Word.Document doc = msWord.Documents.Open(ref file, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null, ref obj_null);
    
        doc.ActiveWindow.Selection.WholeStory();
        doc.ActiveWindow.Selection.Copy();
    
        string data = doc.Content.Text;
        doc.Close(ref obj_null, ref obj_null, ref obj_null);
        msWord.Quit(ref obj_null, ref obj_null, ref obj_null);
    
        return data;
    }

    My code is running successfully. The problem is, it is not recognizing the "new line". What I want is to display content of word file "as it is" mean to say that there should be a new line in label control as it's there in word file.

    Hope, I am making sense.

    Thanks in advance

    • Moved by Cindy Meister MVPModerator Wednesday, July 11, 2012 1:44 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Monday, July 9, 2012 6:40 PM

Answers

  • Hi learner

    The issue is that Word uses ANSI 13 to represent a new paragraph. Most WindowsForms controls use something else, I believe it's ANSI10 + ANSI13. So you need to replace ANSI character 13 in the string you're getting from Word with the character the control you're using expects/requires.

    As your question isn't related to the VSTO technology I'd like to move it to the Word for Developers forum?


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by learner.net Wednesday, July 11, 2012 6:26 PM
    Tuesday, July 10, 2012 3:09 PM
    Moderator
  • Hi learner

    I'm afraid I'm not familiar with asp.net, so I have no idea what the ANSI code would be. It might be better to ask in an asp.net forum, now that you know the problem is converting ANSI 13 to ???


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by learner.net Wednesday, July 11, 2012 6:26 PM
    Wednesday, July 11, 2012 3:36 PM
    Moderator

All replies

  • Hi learner

    The issue is that Word uses ANSI 13 to represent a new paragraph. Most WindowsForms controls use something else, I believe it's ANSI10 + ANSI13. So you need to replace ANSI character 13 in the string you're getting from Word with the character the control you're using expects/requires.

    As your question isn't related to the VSTO technology I'd like to move it to the Word for Developers forum?


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by learner.net Wednesday, July 11, 2012 6:26 PM
    Tuesday, July 10, 2012 3:09 PM
    Moderator
  • Hi,

    Thanks for the reply. Mine is a ASP.NET application.

    I am quite new to this, so would request you to provide some code for the same.

    Aslo, sorry for choosing wrong forum. Please move it to the right one.

    Waiting for your reply

    Regards

    Tuesday, July 10, 2012 9:13 PM
  • Hi learner

    I'm afraid I'm not familiar with asp.net, so I have no idea what the ANSI code would be. It might be better to ask in an asp.net forum, now that you know the problem is converting ANSI 13 to ???


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by learner.net Wednesday, July 11, 2012 6:26 PM
    Wednesday, July 11, 2012 3:36 PM
    Moderator
  • Thanks for the guidence.
    Wednesday, July 11, 2012 6:26 PM