简体   繁体   English

打开文件,文件名中包含空格

[英]Open file with blank spaces in filename

How it understands the blank spaces like separated args: 它如何理解空格,如分隔的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: 当我启动另一个应用程序实例时,我使用参数通过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. 带有空格的文件名可以很好地加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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