构建目录路径/和双引号

use*_*420 -2 c# asp.net format quote

我正在尝试构建一个将文件放在那里的路径,但我正在使用string.Format并且/参数之间没有出现.这是我的例子:

    string pdfFile = string.Format("{0}{1}{2}{3}", "MyPDF", "/", this.IdPDF, "/");
Run Code Online (Sandbox Code Playgroud)

有人能告诉我为什么/之间JPGId没有出现?

这是感谢Damith和其他所有人的答案!

string pdfFile = string.Format("{0}/{1}", "MyPDF", this.idPDF);
Run Code Online (Sandbox Code Playgroud)

Jul*_*ano 6

用途Path.Combine:

string folder = System.IO.Path.Combine(@"\MyPDF", Id, "sales.pdf");
Run Code Online (Sandbox Code Playgroud)

这会产生类似的东西\MyPDF\2\sales.pdf.通常,Path.Combine将连接所有参数以构建路径.从MSDN示例:

string[] paths = {@"d:\archives", "2001", "media", "images"};
string fullPath = Path.Combine(paths);
Run Code Online (Sandbox Code Playgroud)

fullPath会的d:\archives\2001\media\images.