简体   繁体   中英

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):

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

Like this:

...

string result = ...;

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

...

Try:

string result = openFileDialog.FileName;

File names with spaces are loaded fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM