システム パスで文字列変数を使用するにはどうすればよいですか? 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";
私が試した2番目のケースでは"Content-Disposition: file;file_name=\" + file_name +\"
、しかし、私はこれを得ています:
認識できないエスケープ シーケンス、予期しない文字 '\'
これはパスで変数を使用する正しい方法ですか?
ありがとうございました。