如何在系统路径中使用字符串变量?以下是 C# 代码示例:
public class Test
{
public Item Met()
{
string file_name = "sample1.pdf";
///I' m just giving the code where I have the problem, not full code
/// kindly ignore the syntax errors if any
FileStream fileStream = File.OpenRead("c:\\Temp\\sample1.pdf");
// Here I tried "C:\\Temp\\" + file_name //
string requestBodyStart = "\r\n\r\n--BOUNDARY\r\n" +
"Content-Type: application/xml\r\n" +
"Content-Disposition: form-data\r\n" +
"\r\n" +
envDef + "\r\n\r\n--BOUNDARY\r\n" +
"Content-Type: application/pdf\r\n" +
"Content-Disposition: file;filename=\"sample2.pdf\"; documentId=1\r\n" +
"\r\n"; ///Here in place of "sample.pdf" I want to use variable name
string requestBodyEnd = "\r\n--BOUNDARY--\r\n\r\n";
在第二种情况下,我尝试了"Content-Disposition: file;file_name=\" + file_name +\"
但我得到了这个:
无法识别的转义序列,意外的字符 '\'
这是在路径中使用变量的正确方法吗?
谢谢你。