c# save word file and open it using .net framework

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aliatef
    New Member
    • Apr 2013
    • 1

    c# save word file and open it using .net framework

    hi
    i have created application using gembox
    i create a word file and save data on it
    but i want after saving it itis opened to me using microsoft word directly

    it is the code


    Code:
                    DocumentModel document1 = new DocumentModel();
    
                    Section section1 = new Section(document1);
                    document1.Sections.Add(section1);
    
                    Paragraph paragraph1 = new Paragraph(document1) { ParagraphFormat = { RightToLeft = true } };
                    section1.Blocks.Add(paragraph1);
                    string result = "x  " + " ' " + textBox7.Text + " '  " + textBox3.Text + "    x ";
                    Run run = new Run(document1, result) { CharacterFormat = { RightToLeft = true } };
    
                    paragraph1.Inlines.Add(run);
                    document1.Save("report1.docx");
    i want report1 be opened after itis being saved
    please help ....
    Last edited by Rabbit; Apr 17 '13, 03:37 PM. Reason: Please use code tags when posting code.
  • SirZizo
    New Member
    • Apr 2013
    • 4

    #2
    you can use openfiledialog control

    then use
    Code:
      
    txtre.Text = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\")) +
                     "\\Result.docx";
    
     private void btnres_Click(object sender, EventArgs e)
            {
                openFileDialog2.CheckFileExists = false;
                openFileDialog2.FileName = txtre.Text;
                openFileDialog2.InitialDirectory = !Directory.Exists(txtre.Text)
                                           ? Path.GetPathRoot(Environment.SystemDirectory)
                                           : txtre.Text;
                openFileDialog2.ShowDialog(this);
    
            }
    
      private void openFileDialog2_FileOk(object sender, CancelEventArgs e)
            {
                txtre.Text = openFileDialog2.FileName;
            }
    
    System.Diagnostics.Process.Start(txtre.Text);
    with Success !

    Comment

    Working...