物理路径,但C#中预计有虚拟路径 [英] a physical path, but a virtual path was expected in C#

查看:143
本文介绍了物理路径,但C#中预计有虚拟路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从名为strjobID的文件夹下载恢复文件,并且文件名存储在网格视图的CommandArgument中,但在执行时我正在获取此例外



''D:/AdminApp/Jobportals/Utils/ApplicantFiles/27/directory.txt'' 是一个物理路径,但预计会有虚拟路径。



请为此建议一些解决方案

I am trying to download resume file from folder nameed as strjobID and file name is stored in CommandArgument of grid view , but while execution I am Getting this Exception

''D:/AdminApp/Jobportals/Utils/ApplicantFiles/27/directory.txt'' is a physical path, but a virtual path was expected.

Please suggest some solution for this

try
{
   Button Button1 = (Button)sender;
    
   string strFilename = ((Button)sender).CommandArgument;
   string strURL = Server.MapPath(@"" + "~/Utils/ApplicantFiles/" + strjobID + "/" + strFilename);
   WebClient req = new WebClient();
   HttpResponse response = HttpContext.Current.Response;
   response.Clear();
   response.ClearContent();
   response.ClearHeaders();
   response.Buffer = true;
   response.AddHeader("Content-Disposition", "attachment;filename=\"" + strURL + "\"");
   byte[] data = req.DownloadData(Server.MapPath(strURL));
   response.BinaryWrite(data);
   response.End();
}

推荐答案

我认为这一行是错误的:



byte [] data = req.DownloadData(Server.MapPath(strURL));



你已经在strURL上做了MapPath。所以,它已经是一个本地路径,但是你将它传递给一个需要转换虚拟路径的方法。
I assume this line is the error:

byte[] data = req.DownloadData(Server.MapPath(strURL));

You did MapPath on strURL already. So, it''s already a local path, but you pass it to a method that expects a virtual path to convert.


这篇关于物理路径,但C#中预计有虚拟路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆