Big Smile
Big Smile

Reputation: 41

DOC TO XPS FILE DOCUMENT

I just wanted to know how can I convert my document .doc path to xps file document.

If anyone can help I would be glad to know the code in VB.NET since I googled it already but unfortunately I can't find best answer to my question.

Thank you

Upvotes: 1

Views: 1331

Answers (1)

John Sibly
John Sibly

Reputation: 23096

I did this using the following code in a console application. You'll need to reference the Microsoft.Office.Interop.Word assembly (version 12 on later for the ability to generate XPS files) and import the namespace.

The code in VB is:

Option Explicit On

Module Module1

Sub Main()
    Dim word As _Application
    Dim doc As _Document

    word = New Application
    doc = word.Documents.Open("C:\test.doc")
    doc.SaveAs("C:\test.xps", WdSaveFormat.wdFormatXPS)
    word.Quit()
End Sub

End Module

And in C#:

using Microsoft.Office.Interop.Word;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            _Application word = new Application();
            _Document doc = word.Documents.Open(@"C:\test.doc");
            doc.SaveAs(@"C:\test.xps", WdSaveFormat.wdFormatXPS);
            word.Quit();
        }
    }
}

Upvotes: 1

Related Questions