Thursday, 09 December 2010 04:10

Solutions to Open Word in C#, VB.NET

No matter what users want to do on Word document, they should open it. This guide demonstrates several solutions to open Word in C# and VB.NET via Spire.Doc for .NET.

Open Existing Word

Spire.Doc for .NET provides a Document(String) constructor to enable users to initialize a new instance of Document class from the specified existing document.

[C#]
  Document document = new Document(@"E:\Work\Documents\Spire.Doc for .NET.docx");
[VB.NET]
Dim document As New Document("E:\Work\Documents\Spire.Doc for .NET.docx")

Spire.Doc for .NET also provides Document.LoadFromFile(String) method of Document class to open a Word document. The Word document can be .doc(Word 97-2003), .docx(Word 2007 and 2010) and .docm(Word with macro).

[C#]
  Document document = new Document();
            document.LoadFromFile(@"E:\Work\Documents\Spire.Doc for .NET.docx");
[VB.NET]
 Dim document As New Document()
            document.LoadFromFile("E:\Work\Documents\Spire.Doc for .NET.docx")
          

Open Word in Read Mode

Spire.Doc for .NET provides Document.LoadFromFileInReadMode(String, FileFormat) method of Document class to load Word in Read-Only mode.

[C#]
            Document document = new Document();
            document.LoadFromFileInReadMode(@"E:\Work\Documents\Spire.Doc for .NET.docx",FileFormat.Docx);
[VB.NET]
            Dim document As New Document()
            document.LoadFromFileInReadMode("E:\Work\Documents\Spire.Doc for .NET.docx", FileFormat.Docx)

Load Word from Stream

Spire.Doc for .NET provides the constructor Document(Stream) to initialize a new instance of Document class from specified data stream and the method Document.LoadFromStream(Stream, FileFormat) to open document from Stream in XML or Microsoft Word document.

[C#]
            Stream stream = File.OpenRead(@"E:\Work\Documents\Spire.Doc for .NET.docx");
            Document document = new Document(stream);
OR
            Stream stream = File.OpenRead(@"E:\Work\Documents\Spire.Doc for .NET.docx"); 
            Document document = new Document();
            document.LoadFromStream(stream, FileFormat.Docx);
[VB.NET]
            Dim stream As Stream = File.OpenRead("E:\Work\Documents\Spire.Doc for .NET.docx")
            Dim document As New Document(stream)
OR
            Dim stream As Stream = File.OpenRead("E:\Work\Documents\Spire.Doc for .NET.docx")
            Dim document As New Document()
            document.LoadFromStream(stream, FileFormat.Docx)

Spire.Doc, an easy-to-use component to operate Word document, allows developers to fast generate, write, edit and save Word (Word 97-2003, Word 2007, Word 2010) in C# and VB.NET for .NET, Silverlight and WPF.

Published in Document Operation
Thursday, 21 October 2010 14:19

Word Page Setup in C#, VB.NET

The sample demonstrates how to work with Word page setup.

Published in Setup
Thursday, 21 October 2010 14:16

Word document setup in C#, VB.NET

The sample demonstrates how to set document properties.

Published in Setup
Thursday, 21 October 2010 13:51

Word merge event handler in C#, VB.NET

The sample demonstrates how to handle merge event.

Published in Mail Merge
Thursday, 21 October 2010 13:44

Word to xml in C#, VB.NET

The sample demonstrates how to export doc document to XML file.

 

Published in Convertors
Thursday, 21 October 2010 13:25

Word table in C#, VB.NET

The sample demonstrates how to create table in word document.

Published in Context
Thursday, 21 October 2010 13:20

Word indent in C#, VB.NET

The sample demonstrates how to indent paragraph.

Published in Formating
Thursday, 21 October 2010 12:31

Word font and color in C#, VB.NET

The sample demonstrates how to set font and color.

Published in Formating

This sample demonstrates how to export data table to text/sylk/csv/dif file.

The picture above represents using Excel application to open a SYLK type output file.

Published in Demo
Sunday, 01 August 2010 18:50

Data Export SQL Script in C#, VB.NET

This sample demonstrates how to export data table to sql script.

Published in Demo
Page 5 of 10