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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening DOC, XLS, JPG, WAV, ... Files

Status
Not open for further replies.

skuhlman

Programmer
Jun 10, 2002
260
US
Our current FoxPro application allows the users to open files of any format. It does this by opening Windows Explorer starting in the directory where the file they want to open is located. Then the user double clicks on the file and windows handles things by opening the file with the replated application. Really, all the work is being done by Windows except for opening the explorer.

Now we have a table containing file names. We want to show these names (possibly in a grid) and have the program open them directly so that they don't have to "wander" through windows explorer. Is there an easy way for VFP to do this without having to set up all kinds of cases for every possible file type?

Any suggestions for an easy way to do this are appreciated. Thanks
 
Check out one of the many threads on the use of ShellExecute() API call.

Rick
 
HI
1. To collect the files in a cursor..
and download.

2. Now assuming you have the file in a variable cFile
(cFile = "MyFile.Ext")
To open it with appropriate application..

DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, STRING cAction, STRING cFileName, ;
STRING cParams, STRING cDir, INTEGER nShowWin
ShellExecute(0,"open",cFile,"","",1)

:)


ramani :)
(Subramanian.G)
 
Here is my good deed for the day. I plan on upgrading my website soon and adding a fox link with samples. I add this to it. Copy the code into a prg file. Go ahead and run it. It will create a file named "c:\deltabg.txt" and then open it based on its extension (notepad). You can also send it right to print or pass other parameters. This code also works with a URL. applaunch("
Cheers

lcFileName = "c:\deltabg.txt"
IF FILE("&lcFilename")
IF MESSAGEBOX("File deltabg.txt alreay exists",4+32,"Delta Business Group") = 6
DELETE FILE (lcFileName)
ELSE
MESSAGEBOX("No action taken...",0,"Delta Business Group")
RETURN
ENDIF
ENDIF

STRTOFILE("Hello from Delta Business Group: appLaunch(lcFileName)

* use this one to send it right to print
* appLaunch(lcFileName,"Print")


FUNCTION appLaunch
***********************************************************************
PARAMETER tcOutFile,tcCmd

IF PCOUNT() < 1
MESSAGEBOX(&quot;You did not provide a filename.&quot;,&quot;AppLauch Method&quot;)
RETURN
ENDIF

IF PCOUNT() < 2
tcCmd = &quot;Open&quot;
ENDIF

tcCmd = PROPER(tcCmd)

* This code was originally located in Ken Levy's DBF2XML program.

* API Call to communicate with an application based on the registered
* file-type.
* For example:
* On my computer txt is notepad; DOC is word

DECLARE INTEGER ShellExecute ;
IN SHELL32.DLL ;
INTEGER nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow

* tip: to determine commands available for each filetype
* Launch explorer
* go to View / Folder Options
* Select the File Type Tag
* go to the item you wish to look up (example Acrobat)
* Press Edit
* You will see acrobat has Open, Print, and Printto option types.

IF !FILE(tcOutFile)
MESSAGEBOX(tcOutFile + &quot; does not exist!&quot;,&quot;AppLauch Method&quot;)
ELSE

* play with this.
* by adding the ,0 instead of ,1 I was able to get it to
* print directly without opening the document on my sceen.


* this is handy if you wish to print a pdf, word document,
* spreadsheet, text file, etc. from within your applicaiton.
IF tcCmd = &quot;Print&quot;
lnFileStatus = ShellExecute(0,&quot;&tcCmd&quot;,tcOutFile,&quot;&quot;,&quot;&quot;,0)
ELSE
lnFileStatus = ShellExecute(0,&quot;&tcCmd&quot;,tcOutFile,&quot;&quot;,&quot;&quot;,1)
ENDIF
DO CASE
CASE lnFileStatus > 32
* successful open
CASE lnFileStatus = 2
MESSAGEBOX(&quot;Bad Association (for example, invalid URL)&quot;,;
&quot;AppLauch Method&quot;)
CASE lnFileStatus = 29
MESSAGEBOX(&quot;Failure to load application&quot;,&quot;AppLauch Method&quot;)
CASE lnFileStatus = 30
MESSAGEBOX(&quot;Application is busy&quot;,&quot;AppLauch Method&quot;)
CASE lnFileStatus = 31
MESSAGEBOX(&quot;No application association with specified &quot;+;
&quot;command: &quot; + tcCmd,&quot;AppLauch Method&quot;)
OTHERWISE
MESSAGEBOX(&quot;Unknown Error&quot;,&quot;AppLauch Method&quot;)
RETURN .F.
ENDCASE
ENDIF


Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top