C# how to read text из.docx through a stream

The problem occurs precisely with .docx files, files .txt through StreamReader are read quite easily.

Here is the method:

public string DownloadToEditor(string FilePath)
    {
        using (StreamReader reader = new StreamReader(FilePath, Encoding.Default))
            {
                return TextForEditor = reader.ReadToEnd();
            }
    }

How to fix it? do I have to use some third-party library?

Author: Имя Фамилия, 2019-07-13

1 answers

Do I have to use some third-party library?

Yes, absolutely. Well, or you can write your own file parser on the specifics of mikrsoft, but I suspect that it will take you 5 years. But without third-party libraries, as you wish.

The Open XML SDK will do.

I strongly advise against using the Interop path. Too many difficulties + restriction that the office itself would stand on the car.

You can use the nuggets OpenXML or wrappers around OpenXML. For example, you can use the DocX wrapper from xceed (it is here that you turn your eyes! This is what I recommend most of all)

 0
Author: Andrew, 2019-09-14 22:31:17