File paths in Processes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to use the Process object to launch an application (and in some
cases open a file), however whenever there are any spaces in process FileName
or Arguments I get an error stating the file cannot be found. For example:

Dim p As New Process
Dim pi As New ProcessStartInfo

pi.Arguments = "S:\A Folder\Another Folders\My File.xls"
pi.FileName = "Excel.exe"
p.StartInfo = pi
p.Start()

This code causes a 'file not found' error even when the filepath is correct.
I was wondering if I need to substitute the spaces with a difference
character to get this code to work. Any suggestions would be appreciated.

p.s. The example is for Excel, but I may not necessarily be using that
process.
 
This works ok for me.

Can I suggest you go to the Start / Run prompt and type in excel.exe and see
if it's the path to Excel that is causing the problem?
 
Nope, my excel seems to be working fine.

Here is an example of the exact path: "s:\Application Data\IBS Reports\Voids
Current Beta.xls". Excel loads up then says "S:\Application.xls" can't be
found, then "data.xls" can't be found, etc. etc.
 
Enterprise Andy said:
I am trying to use the Process object to launch an application (and in
some
cases open a file), however whenever there are any spaces in process
FileName
or Arguments I get an error stating the file cannot be found. For example:

Dim p As New Process
Dim pi As New ProcessStartInfo

pi.Arguments = "S:\A Folder\Another Folders\My File.xls"

Try to put the filename into double quotes:

\\\
pi.Arguments = """S:\A Folder\Another Folders\My File.xls"""
///
 
Back
Top