0

I am sorry if this Question is not well structured but this is a question that has been puzzling for a while now.

I know how to Read a Text file from the Open file Dialog into a Rich Text box using

    DialogResult DR = openFileDialog1.ShowDialog();

    if (DR == DialogResult.OK)
    {
         string txt = openFileDialog1.SafeFileName;
         FileStream textFile = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
         StreamReader doc = new StreamReader(textFile);
         GetCurrentTextbox().Text = doc.ReadToEnd();
         tabControl1.SelectedTab.Text = txt;
     }

This works perfectly for Ordinary Text files but the Problem is that if this File was created using Wordpad or MsWord, it shows something like

File

Pls what can i do????

4

1 回答 1

2

这对普通文本文件非常有效,但问题是如果这个文件是使用写字板或 MsWord 创建的,它会显示类似

是的,因为这些不是文本文件 - 但您正试图将它们作为文本文件读取。

如果您需要阅读 Word/Wordpad 文档,则需要使用 Office Interop,或者可能需要使用能够理解文件格式的第三方库。无论哪种方式,您都无法将Text控件的属性设置为任何内容来获取格式化文本。您也许可以将其转换为 RTF,然后使用RichTextBox.

于 2013-07-02T20:49:00.687 回答