asp.net mvC语言 不是来自网络驱动器的有效虚拟路径文件



下面是我的代码,我收到以下错误。请帮忙..

private const string FILEPATH = @"\**.**.**.**D:BCPResultCust_File.txt";
string filePath = string.Empty;
filePath = Server.MapPath(FILEPATH);
string fileName = Path.GetFileName(filePath);
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.TransmitFile(filePath);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Flush();
Response.End();
错误 :- \++.++

.++.++\D:\BCPResult\Cust_File.txt' 不是有效的虚拟路径。

在 Windows 资源管理器中试用:start run: \**.**.**.**D:BCPResultCust_File.txt

这将是\**.**D$BCPResultCust_File.txt

但是,如果您使用它,则它是网络路径,而不是相对于站点的虚拟路径,因此您不需要Server.MapPath()它将为您提供:

C:inetpubwwwroot**.**D$BCPResultCust_File.txt

其中c:inetpubwwwroot是 IIS 根(不是您的应用程序)(它可能不同) - 这是因为\部分在应用程序根路径之外重置。 如果您这样做Server.MapPath("x")它将基于应用程序的根目录。

最新更新