Solved

Add Word to winforms application

Posted on 2007-11-15
9
582 Views
Last Modified: 2013-11-26
Hi,

I have a listbox on my winforms application. This listbox loads all my available files for viewing from a specific directory. I want to add a Word document on the right side of my application (form1) and then every time a user clicks on a file in the listbox it opens the file on the right hand side in Word.

How do I do that? and is it possible?
0
Comment
Question by:ALawrence007
  • 5
  • 3
9 Comments
 
LVL 8

Expert Comment

by:Wikkard
Comment Utility
I dont think that you can embed a word editor onto a form.
I might be wrong.
0
 
LVL 8

Assisted Solution

by:Wikkard
Wikkard earned 450 total points
Comment Utility
You could however automate an instance of word to open the file easily enough.
0
 
LVL 8

Expert Comment

by:Wikkard
Comment Utility
Add a reference to Microsoft.Word (COM).
Then you can create an instance of word and open your document in it.
ie.
[C#]
 Microsoft.Office.Interop.Word._Application oWord = new ApplicationClass();
            try
            {
                object filename = this.txtWordDoc.Text;
                oWord.Visible = false;
               
              //  oWord.Activate();
                oWord.Documents.Open(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
catch (Exception ex)

{

}

ill convert it to VB for you

             

0
 
LVL 10

Assisted Solution

by:vadim63
vadim63 earned 50 total points
Comment Utility
You can use the WebBrowser control. Something like:
WebBrowser1.Navigate("c:\test.doc")
Look here:
http://support.microsoft.com/default.aspx?scid=kb%3bEN-US%3b304643
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Accepted Solution

by:
Wikkard earned 450 total points
Comment Utility
The reference is called "Microsoft Word 11.0 Object Library" the version might be different for you.



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oWord As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application
        Dim filename As String = "c:\oct.doc"
        Dim missing As Object = System.Reflection.Missing.Value
        oWord.Visible = True
        oWord.Documents.Open(filename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
        oWord.Activate()

        Dim rc As MsgBoxResult = MsgBox("Do you want to close word ? ", MsgBoxStyle.YesNo)

        If rc = MsgBoxResult.Yes Then
            oWord.ActiveDocument.Close(missing, missing, missing)
            oWord.Quit()
        End If


    End Sub
0
 

Author Comment

by:ALawrence007
Comment Utility
Wow,

These are all great suggestions. One more question: If I want to add settings i.e open in read only mode? Or something like that?

If I open a XML file, can I apply the stylesheet this way? With the settings?
0
 
LVL 8

Assisted Solution

by:Wikkard
Wikkard earned 450 total points
Comment Utility
You definitely can do both of those thing.

Notice in the code above we use a variable called missing alot. It's just a placeholder for the missing parameters. You need to tell the open method to open read only.

Just change the line
oWord.Documents.Open(filename, missing, true, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)

Ill find out how to do XSL transform.
0
 

Author Comment

by:ALawrence007
Comment Utility
I would appretiate the XSL transform question.

Thanks
0
 

Author Closing Comment

by:ALawrence007
Comment Utility
Wikkard, Based on what you gave me I found my solution.
vadim63, your suggestion was also helpful.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now