Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening files given their path and name

Status
Not open for further replies.

leassaf

Instructor
May 20, 2001
49
IL
I’ve been looking for some way of opening files given their full name (path included). The only way I’ve found was the “Microsoft.VisualBasic” namespace, providing the old “Shell” function. However, this function only runs executable files.
Suppose I want to open a PowerPoint or Excel document given the following string: "C:\My Documents\FileToOpen.xls". I refrain from using the application’s dll by creating an object of the file’s type (ex: Excel.Application) because I want the Operating System to decide which application should be used to open the specified document.

Does anyone know some way of opening files?
 
Create an instance of the ProcessStartInfo class, and set the UseShellExecute property to true (you'll need to set a few other properties too). Then create a new instance of the Process class, and pass your ProcessStartInfo instance to it when you call the Start method.

Chip H.




If you want to get the best response to a question, please check out FAQ222-2244 first
 
' Declare and instantiate a new process component.
Dim myproc As System.Diagnostics.Process
myproc = New System.Diagnostics.Process

' Do not receive an event when the process exits.
myproc.EnableRaisingEvents = False
' Start Internet Explorer, passing in a Web page.
myproc.Start("IExplore.exe", "
 
see if this is helpful:

System.Diagnostics.Process.Start(file_name)

anurc
 
Fellows!
You've been of so much help.
Thanks extremely and good night...
 
By the way, the file is opened but the focus is set back to the launching application...
Is there a property that sets the focus to the application that was used to open the file?
 
Let me rephrase that. I need the focus to be set to the launched application (the whose process was started)...
 
I don't see why the focus not set to the launched application if u open the IE file from the above code the focus should move to IE,not tested withn other applications though
check if u set the TopMot property of your FORM
Nouman
 
Actually, there's something quite weird going on.
My application allows launching office applications such as Word, Excel, PowerPoint.
Whenever PowerPoint is launched, the focus remains at the PowerPoint app. As for Word and Excel, once their process has started, the focus is set back to my application.
I therefore am trying to workaround this behaviour and set the focus in some other way.
Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top