|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Open MS Word document using VB.NET Hello, How can I open MS Word document using VB.NET? |
#2
| |||
| |||
Re: Open MS Word document using VB.NET Below is the code to open Word document. Code: 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 aDoc.Activate() ' 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 |
#3
| |||
| |||
Open MS Word document using Asp.NET This given code is to Open MS Word document using Asp.NET Code: Try 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 stream.Close() Response.Clear() Response.ContentType = "application/word" Response.AddHeader("Content-disposition", "filename=output.doc") Response.OutputStream.Write(bytes, 0, bytes.Length) Response.OutputStream.Flush() Response.OutputStream.Close() Response.Flush() Response.Close() Catch ex As Exception Throw ex End Try |
![]() |
|
Tags: open word document, using aspnet, using vbnet |
Thread Tools | Search this Thread |
|
![]() | ||||
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 |