C# 返回位于特定路径中的文件
我编写了一个方法,以便使用返回类型C# 返回位于特定路径中的文件,c#,file,httpresponsemessage,C#,File,Httpresponsemessage,我编写了一个方法,以便使用返回类型HttpResposeMessage返回一个文件。我使用以下代码来附加文件 file.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = newFileName }; file.Content.Headers.ContentType = new MediaTypeHea
HttpResposeMessage
返回一个文件。我使用以下代码来附加文件
file.Content.Headers.ContentDisposition =
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = newFileName
};
file.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");
return file;
如何在文件名中指定特定路径。
我做了这样的事
fileName = "C://Templates/Order.pdf"
但这会将文件名重命名为C:\u Templates\u Order.pdf
我需要的是遍历路径并获取文件。您需要使用此simbol
\
而不是/
来输入文件名
file.Content.Headers.ContentDisposition =
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = newFileName
};
file.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");
return file;
fileName = "C:\\Templates\\Order.pdf";
您需要使用此simbol
\
而不是/
来输入文件名
fileName = "C:\\Templates\\Order.pdf";
您可以使用字符串引号前面的@符号声明字符串文字:
fileName = @"C:\templates\order.pdf"
或者你可以双倍地避开反斜杠
fileName = "C:\\templates\\order.pdf"
您可以使用字符串引号前面的@符号声明字符串文字:
fileName = @"C:\templates\order.pdf"
或者你可以双倍地避开反斜杠
fileName = "C:\\templates\\order.pdf"
我想你对文件命名和路径在windows中的工作方式感到困惑,可能是时候上复习课了。我想你对文件命名和路径在windows中的工作方式感到困惑,可能是时候上复习课了