user5000935
user5000935

Reputation:

Open file with blank spaces in filename

How it understands the blank spaces like separated args:

            const string args = "";

            string result = args + openFileDialog; //For test purpose only
            var app = new ProcessStartInfo(Application.ExecutablePath, result);

            Proc

When I start the other instance of my aplication, I use the argument to read the file using a StreamReader:

_fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8, false, 512, true);

var result = streamReader.ReadToEnd();

My log file output is like this (I've removed some info so it's more readable):

Upvotes: 0

Views: 2083

Answers (2)

Yacoub Massad
Yacoub Massad

Reputation: 27861

Try wrapping the arguments with double-quotes. Note the space before the \ like in " \"".

Like this:

...

string result = ...;

result = " \"" + result + " \"";

...

Upvotes: 1

timoconnell
timoconnell

Reputation: 129

Try:

string result = openFileDialog.FileName;

File names with spaces are loaded fine.

Upvotes: 1

Related Questions