1

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.

3 Answers 3

3

Try quoting your path:

startInfo.Arguments = "\"" + "C:\Users\dj\Desktop\da ba.xls" + "\"";

Tim

Sign up to request clarification or add additional context in comments.

Comments

2

Try using a string literal

startInfo.Arguments = @"C:\Users\un\Desktop\file with space"

Comments

0

This way works

"\"" + @dialog.FileName + "\"";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.