When the button is clicked, I want the file (it's a XPS document) to be opened in windows.
The file will be in the same directory as the visual basic project.
Therefore, I need the code to open the file using "app.Path".
Any solutions?

Here's the [MSDN article on the Shell Function](http://msdn.microsoft.com/en-us/library/aa242087%28v=VS.60%29.aspx).  Which should do what you want. basically Shell(""path""), and yes the double quotes are on purpose. :)  If I remember correctly the App object applies to the vb project and the path property is read-only and poins to the directory that the project or .exe is sitting.  As long as you have .xps associated with a program in windows then Shell should work.

You must get the full path of the file, like this

App.Path & "\" & <name.ext>

Once you have it, you can call the ShellExecute API function passing as param the string you got before.

in order to execute your task , you can use the following:-

Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
            As Long) As Long
Const SW_SHOW = 5

And Finally call the function in following way :-

Private Sub Command1_Click()
    Dim Filename, MyPath As String
    Filename = "test.xps"
    MyPath = App.Path & "\" & Filename
    ShellExecute hwnd, "open", MyPath, vbNullString, App.Path, SW_SHOW
End Sub

hope this helps you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.