File paths in Processes

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.
 
J

JohnFol

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?
 
G

Guest

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.
 
H

Herfried K. Wagner [MVP]

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"""
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top