I was already able to load a .docx file into my wpf application but it doesn't seem to show up in my richtextbox:
if (openFile.ShowDialog() == true)
{
// Open document
string originalfilename = System.IO.Path.GetFullPath(openFile.FileName);
if (openFile.CheckFileExists)
{
var document = DocX.Load(originalfilename);
string contents = document.Text;
rtfMain.Document = contents;
MessageBox.Show("file loaded");
}
}
The contents string variable is not accepted by the richtextbox in wpf. Any idea how to make it work?
That code shouldn't compile,
RichTextBox.Documentis of typeFlowDocument, and you are assigning it to astring.Maybe you should look for ways to convert a .docx file to a
FlowDocumentyou can assign to theRichTextBox.There is a popular tool you can use which is called: Word to XAML
Another options are: