How can we open the word documen on front of the main form?
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();
oWord.Visible = true;
Object oTemplatePath = System.Windows.Forms.Application.StartupPath + "\\Sozlesme.docx";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted Jul 6, 2023, 8:14 AM EDT
Hi Mehmet
1.To open a Word document in front of the main form, you can follow these steps:
using Word = Microsoft.Office.Interop.Word;2.Create an instance of the Word Application:
Word.Application oWord = new Word.Application();3.Set the visibility of the Word Application to true:
oWord.Visible = true;4.Open the Word document and assign it to a Document object:
Here's the updated code snippet:
using Word = Microsoft.Office.Interop.Word; // ... object oMissing = System.Reflection.Missing.Value; object oTrue = true; object oFalse = false; Word.Application oWord = new Word.Application(); Word.Document oWordDoc = new Word.Document(); oWord.Visible = true; object oTemplatePath = System.Windows.Forms.Application.StartupPath + "\\Sozlesme.docx"; oWordDoc = oWord.Documents.Open(oTemplatePath, oMissing, oTrue, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);Mehmet FatihRank #1,475 · 1.1K reputationPosted Jul 6, 2023, 10:05 AM EDT
Thanks for your intrest Mohamed, I have tried y our codes but it gives an error in the other codes. All I want is to open a word document on the top of main form as in the picture.
Deepak RawatRank #646 · 3.7K reputationPosted Jul 6, 2023, 12:47 PM EDT
To open a Word document in front of the main form using C#, you can follow these steps:
Ensure you have added the necessary references to your project. Right-click on your project in Visual Studio, select "Add" -> "Reference", and then browse and select the "Microsoft.Office.Interop.Word" assembly.
Import the required namespaces at the top of your code file:
using Word = Microsoft.Office.Interop.Word;// Create the Word application object Word.Application oWord = new Word.Application(); // Make the Word application visible oWord.Visible = true; // Specify the path to your Word document string templatePath = System.Windows.Forms.Application.StartupPath + "\\Sozlesme.docx"; // Open the Word document Word.Document oWordDoc = oWord.Documents.Add(templatePath);In this code, we create a new instance of the
Word.Applicationobject, set itsVisibleproperty totrueto make the Word application window visible, and then provide the path to the Word document using thetemplatePathvariable. Finally, we use theDocuments.Add()method to open the document in the Word application.Make sure to adjust the
templatePathvariable to the correct path and filename of your Word document.Mehmet FatihRank #1,475 · 1.1K reputationPosted Jul 6, 2023, 5:01 PM EDT
Normally, my codes are opening the word on the front of main form. But after after compiling the project it isn't opening on the front of the main form. Your codes are the same.
Mehmet FatihRank #1,475 · 1.1K reputationPosted Jul 15, 2023, 9:12 AM EDT
I have solved this problem by adding this code "oWord.ShowAnimation = true;"