Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 19-01-2009
Join Date: Dec 2008
Posts: 19
Open MS Word document using VB.NET


How can I open MS Word document using VB.NET?
Reply With Quote
Old 19-01-2009
Join Date: Apr 2008
Posts: 1,948
Re: Open MS Word document using VB.NET

Below is the code to open Word document.

Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) '
' Use the custom dialog to get the title of the document from the user
Dim theQueryDialog As New TitleQuery
If theQueryDialog.ShowDialog() = DialogResult.OK Then

Dim missing As Object = System.Reflection.Missing.Value
Dim fileName As Object = "normal.dot"
' template file name
Dim newTemplate As Object = False
Dim docType As Object = 0
Dim isVisible As Object = True
' Create a new Document, by calling the Add function in the Documents collection
Dim aDoc As Word.Document = WordApp.Documents.Add(fileName, newTemplate, docType, isVisible)
' need to see the created document, so make it visible
WordApp.Visible = True
' Global Constant enumerations are members of Word and can beassignedproperties
' Set alignment to the center of the document WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
' Toggle the title to a Bold Font
WordApp.Selection.Font.Bold = CInt(Word.WdConstants.wdToggle)
End If ' Type the Text of the Title that was inputted by the user in the CustomDialog WordApp.Selection.TypeText(theQueryDialog.Title); }}
End Sub 'button2_Click
Reply With Quote
Old 19-01-2009
Join Date: May 2008
Posts: 2,008
Open MS Word document using Asp.NET

This given code is to Open MS Word document using Asp.NET

            Dim stream As FileStream = File.Open("d:\word.doc", FileMode.Open) 'replace the location with your word doc.

            stream.Position = 0

            ' Now read s into a byte buffer.
            Dim bytes() As Byte = New Byte(stream.Length) {}
            Dim numBytesToRead As Integer = CType(stream.Length, Integer)
            Dim numBytesRead As Integer = 0
            While numBytesToRead > 0
                ' Read may return anything from 0 to numBytesToRead.
                Dim n As Integer = stream.Read(bytes, numBytesRead, numBytesToRead)
                ' The end of the file is reached.
                If n = 0 Then
                    Exit While
                End If
                numBytesRead += n
                numBytesToRead -= n
            End While

            Response.ContentType = "application/word"
            Response.AddHeader("Content-disposition", "filename=output.doc")

            Response.OutputStream.Write(bytes, 0, bytes.Length)
        Catch ex As Exception
            Throw ex
        End Try
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Open MS Word document using VB.NET"
Thread Thread Starter Forum Replies Last Post
Word cannot open document Scotty816 Windows Software 1 03-10-2011 12:16 PM
Open MS Word Document From JSP Page samualres Software Development 5 12-03-2010 04:20 PM
How to open a word document by a chapter Carlee Windows Software 3 04-09-2009 08:57 PM
Cannot open word document in Mail Mac OS Jason Bourne Operating Systems 3 09-05-2009 05:18 PM
Word 2003 does not open document JanP Windows Software 8 26-03-2009 07:09 PM

All times are GMT +5.5. The time now is 05:34 AM.