0

I have a question.

I have a winform with a richTextBox1, this textbox is readonly, but there is a "Edit"-Button. When you press the Edit-Button, Wordpad or maybe Microsoft Office will open, then you write a Text in the Office tool and after you close word/wordpad, the richTextBox1 will be filled with the Text from the Wordpad.

Is this possible? and if Yes, how ?

steffen1994
  • 247
  • 2
  • 12
  • check this https://stackoverflow.com/questions/10976026/get-data-from-docx-file-like-one-big-string-in-c-sharp – Hossein Jul 23 '18 at 06:33

2 Answers2

1

I might have an answer.

Start up Word with a parameter for the desired file location. Then edit your file and save it. When your app detects that Word has closed or the file has been created, whichever, then you can load that word file into your textbox.

It's a little more long winded than that I'm sure, but that's the gist, totally possible.

I'd begin by looking into Aspose, a library for Microsoft products that exposes simple APIs to use.

Good luck!

Dan Rayson
  • 1,315
  • 1
  • 14
  • 37
1

It is very simple:

private void btnEdit_Click(object sender, EventArgs e)
{
    var myFileName = @"myRtb.rtf";
    //Save your RichTextBox text to a file.
    richTextBox1.SaveFile(myFileName);
    string PathToApp = @"Microsoft Office Word 2007.lnk";
    //Make a System.Diagnostics.Process object
    Process runProg = new Process();
    try
    {
        //With path to your MS Office application
        runProg.StartInfo.FileName = PathToApp;
        //Command line arguments to open file
        runProg.StartInfo.Arguments = "/t" +" "+ myFileName;
        runProg.StartInfo.CreateNoWindow = true;
        //And start your application and also open file
        runProg.Start();
    }
    catch (Exception ex)
    {
    }
}

A documentation to Microsoft Office products command line arguments: https://support.office.com/en-us/article/Command-line-switches-for-Microsoft-Office-products-079164CD-4EF5-4178-B235-441737DEB3A6

koviroli
  • 1,422
  • 1
  • 15
  • 27