Connecting Tech Pros Worldwide Forums | Help | Site Map

open a file

Newbie
 
Join Date: Nov 2008
Posts: 3
#1: Nov 17 '08
here is a easy question for you guys:

How do I open a file? I don't mean import it in vb, I want to open it using the default program.
example: I want to open a mp3 using windows media player when I ask my program to do so...


thanks

lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 860
#2: Nov 18 '08

re: open a file


You can use Shell command for that : )


Rey Sean
Newbie
 
Join Date: Nov 2008
Posts: 3
#3: Nov 18 '08

re: open a file


thanks, with some research I learned how to use shell
Member
 
Join Date: Aug 2008
Location: Sao Paulo - Brasil
Posts: 77
#4: Nov 18 '08

re: open a file


Hi there.

There is an easy way to open no matter what type is your file.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Process.Start("mymusic.mp3")
  3.  
  4. Process.Start("myarq.pdf")
  5.  
  6. Process.Start("mySpreadSheet.xls")
  7.  
  8.  
I hope this help you.
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 860
#5: Nov 18 '08

re: open a file


Quote:

Originally Posted by rpicilli

Hi there.

There is an easy way to open no matter what type is your file.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Process.Start("mymusic.mp3")
  3.  
  4. Process.Start("myarq.pdf")
  5.  
  6. Process.Start("mySpreadSheet.xls")
  7.  
  8.  
I hope this help you.

This will only work on .net project. If the OP is using vb 6, shell command will do.


Rey Sean
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#6: Nov 19 '08

re: open a file


Use the following code:

ShellExecute 0&, "OPEN", "E:\Songs\14-Race\05 - Zara Zara Touch Me (Asian RnB Mix).mp3", "", "", 1

In this replace file name with your filename. Also for this is required:

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
Member
 
Join Date: Aug 2008
Location: Sao Paulo - Brasil
Posts: 77
#7: Nov 19 '08

re: open a file


Quote:

Originally Posted by lotus18

This will only work on .net project. If the OP is using vb 6, shell command will do.


Rey Sean

Hi I'm not using dot.net project. I'm using the free version of VB 2008. Looks like Visual Studio but its not. Either way thank you.
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#8: Nov 20 '08

re: open a file


Dear rpicilli
I also am not using vb.net. I am using VB6 and in that it works fine. In vb 2008 u can check and I think it should work.
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 860
#9: Nov 20 '08

re: open a file


Quote:

Originally Posted by rpicilli

Hi I'm not using dot.net project. I'm using the free version of VB 2008. Looks like Visual Studio but its not. Either way thank you.

What I meant is .NET and not actually "project". Sorry for the previous post : )


Rey Sean
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 860
#10: Nov 20 '08

re: open a file


Quote:

Originally Posted by smartchap

Dear rpicilli
I also am not using vb.net. I am using VB6 and in that it works fine. In vb 2008 u can check and I think it should work.

Try to switch to vb .NET and you will be amazed of this language. I swear : )


Rey Sean
Reply