如何在系統路徑中使用字符串變量?下面是示例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 +\"
第二種情況下但我收到此:
無法識別的轉義序列,意外的字符 '\'
這是在路徑中使用變量的正確方法嗎?
謝謝。
嘗試格式化你的問題的代碼。 – AgentFire 2013-05-07 06:33:26