Opening files from Servoy application

Hi all,

I am looking for a solution to this problem. I want to let the user open files from my Servoy solution running in the standalone client. I have access to the paths to the files, which could be pdf, doc, xsl or other image documents, but I can’t find a decent solution that opens these files in their respective programs.

Searching for a solution, so far I have encountered these possible approaches, but none of them seem to do exactly what I need:

  • display a list of files in a folder (or show an open file dialog)
  • user clicks on file from list and it opens in its native application (Adobe Acrobat, Word, Excel etc.)
  • works in standalone client

In the current implementation of the ‘file’ plugin for Servoy’s Web-client the client “will open the file directly in the appropriate application” after showing the open file dialog. This sounds like what I need, but as far as I can tell this only applies to the web-client.
http://wiki.servoy.com/display/Serv51/newFeatureHighLights

Cybersack’s OLE plugin also sounds like a good solution, but unfortunately all the links to the plugin in this thread are dead and I haven’t been able to find an alternative source.
https://www.servoy.com/forum/viewtopic.php?t=5164

IT2BE provides several plugins that deal with different file types, but the expense of licensing several of these plugins isn’t feasible at this point.

The most likely candidate is ServoyGuy’s COM plugin, although I am not sure at this point if it is easy to implement the automatic detection of filetypes (to open the file in the appropriate software).
http://www.servoyguy.com/servoy_components/servoy_com_plugin

If anyone has a decent solution for this problem, any help is greatly appreciated.

Thanks,

Micah

Try this:

function openFile(_path) {
	var _OS = application.getOSName();

	if (/Windows/.test(_OS)) {
		application.executeProgram('rundll32', 'url.dll,FileProtocolHandler', _path);
	} else if (/Linux|Freebsd/.test(_OS)) {
		application.executeProgram('mozilla', _path);
	} else if (/Mac/.test(_OS)) {
		application.executeProgram('open', _path);
	}
}

Joas,

xdg-open (not mozilla) seems to be the program to open files or urls on Linux.

Rob

Hi mrosenki

You can use Java to open, print or edit any document

	var desktop = Packages.java.awt.Desktop;
	
	var file = new Packages.java.io.File("my_path/my_file1");
	if (desktop.isDesktopSupported())
		desktop.getDesktop().open(file);
	
	var file2 = new Packages.java.io.File("my_path/my_file2");
	if (desktop.isDesktopSupported())
		desktop.getDesktop().print(file2);
	
	var file3 = new Packages.java.io.File("my_path/my_file3");
	if (desktop.isDesktopSupported())
		desktop.getDesktop().edit(file3);

I hope this can help you

Best Regards. Roberto Blasco

Thanks for the quick replies everyone!
I just tested Joas solution (with Rob’s amendment) and it works perfectly fine (Servoy 6.0.6 1232 osx).
Many, many thanks for your help again,

Micah