Reputation: 37
I want to open a file from a Class in C# using a Process, located in a directoy I asked the user.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXCEL.EXE";
startInfo.Arguments = Here goes the directory I asked
Process.Start(startInfo);
The problem, is that when the location of the file indicated by the user has an space," ", excel thinks that I'm sending two sepparate locations. For example with C:\Users\dj\Desktop\da ba excel tries to open " C:\Users\dj\Desktop\da" as one file, and at the same time "ba" as another file. How can I send a location to excel which has an space, without having this error? with an addres like C:\Users\dj\Desktop\daba without an space it works perfectly.
Upvotes: 1
Views: 1927
Reputation:
Try quoting your path:
startInfo.Arguments = "\"" + "C:\Users\dj\Desktop\da ba.xls" + "\"";
Tim
Upvotes: 3
Reputation: 15699
Try using a string literal
startInfo.Arguments = @"C:\Users\un\Desktop\file with space"
Upvotes: 2