7.7.5 system.net.OpenURL() Broken

Hey guys,

After I upgraded my servers to 7.7.5, every time I try and open a file with the system.net.OpenURL() function I get an illegal character error.


If I try and use the Java URLEncoder, it seems to encode the file name string fine, but the system.net.OpenURL() function doesn’t understand the encoding or something because it always comes back with and error that the file cannot be found.


Is there a work around for this?

index 15 is the space in “Order List”. What happens is you take the space out?

Then it works.

The problem is that the file name is randomly generated or could be user generated so it’s not hard coded. I need something that works in all cases. The user can pick what directory they want the file saved in, and that directory path could very well have spaces or other characters that Java doesn’t like for some reason. This worked perfectly fine before the upgrade with 7.7.4, so something changed.

This is what I’m doing, if this helps at all:

[code]def dataExport(tableData, tableName):
“”" This will export data to excel, requires data and the table name for proper export"""
# Import time module to get current time to create file name.
from java.net import URLEncoder
import system
import time
ftime = time.strftime("%d%b%Y", time.localtime())

fileName = tableName + ftime + ".xls"
filePath = system.dataset.exportExcel(fileName, 1, tableData)
if filePath != None:
	encodedName = URLEncoder.encode("file://"+filePath)
	system.net.openURL(encodedName)[/code]

The URLEncoder stuff is new, I was trying to fix it, but this code has worked fine for a couple of years now.

Have you tried URL encoding just the filename part - not the whole URL?

You mean like this?

[code]def dataExport(tableData, tableName):
“”" This will export data to excel, requires data and the table name for proper export"""
# Import time module to get current time to create file name.
from java.net import URLEncoder
import system
import time
ftime = time.strftime("%d%b%Y", time.localtime())

fileName = tableName + ftime + ".xls"
filePath = system.dataset.exportExcel(fileName, 1, tableData)
if filePath != None:
	encodedName = "file://" + URLEncoder.encode(filePath)
	system.net.openURL(encodedName)[/code]

I still get the error that it can’t find the file. I’ve tried every combination of encoding/not encoding that I can think of and I can’t get it to open up files.


I’m seeing the same problem. Have been trying to find a workaround for the better part of a day now.

It won’t even open a file with no spaces in the name that’s in the root directory. With or without encoding.

Try something like this:

path = "/Users/kevin/Documents/Logix 5000 Data Access.pdf"
path = path.replace(' ', '%20')
system.net.openURL("file://" + path)

If this was previously working with spaces in the URL, I’m guessing something changed with Java’s URL class (it got stricter, in some way), because we haven’t changed anything in the system.net.openURL implementation.

Nah, that doesn’t seem to work either, it seems like it’s just putting that %20 as a literal sting path instead of decoding it maybe?

IOException: Failed to open file:///order%20list.xls. Error message: The system cannot find the file specified.

IOException: Failed to open file://c:/order%20list.xls. Error message: The system cannot find the file specified.

I did find something that works using system.util.execute() for now, but… if the path to excel is different then there will be problems so it’s not a very good or permanent solution.

[code]def dataExport(tableData, tableName):
“”" This will export data to excel, requires data and the table name for proper export"""
# Import time module to get current time to create file name.
from java.net import URLEncoder
import system
import time
ftime = time.strftime("%d%b%Y", time.localtime())

fileName = tableName + ftime + ".xls"
filePath = system.dataset.exportExcel(fileName, 1, tableData)
if filePath != None:
	#system.net.openURL(encodedName)
	system.util.execute(["C:\Program Files\Microsoft Office\Office12\excel.exe", filePath])[/code]

Did you try it with a path that’s got the correct capitalization? In your original post the file name is “Order List.xls”, not “order list.xls”

I found a workaround.

[code]from java.awt import Desktop
from java.io import File

if Desktop.isDesktopSupported():
path = system.file.openFile()
file = File(path)

Desktop.getDesktop().open(file)[/code]

Yeah, I actually had the capitalization wrong the first time. Oops… Anyway, I got it working correctly now. I had to leave the double // off of the file: part and I also had to switch out all of the backslashes with front slashes for some reason? Well, it’s working now. Thanks for the help and pointing me in the right direction. Here’s the working code for other people that will probably run into this:

[code]def dataExport(tableData, tableName):
“”" This will export data to excel, requires data and the table name for proper export"""
# Import time module to get current time to create file name.
from java.net import URLEncoder
import system
import time
ftime = time.strftime("%d%b%Y", time.localtime())

fileName = tableName + ftime + ".xls"
filePath = system.dataset.exportExcel(fileName, 1, tableData)
if filePath != None:
	filePath = filePath.replace(' ', '%20')
	filePath = filePath.replace('\\', '/')
	system.net.openURL("file:" + filePath)[/code]

Good work, Doug! :thumb_left: Just to be sure, I verified that it also works in 7.7.4.