本文介绍了物理路径,但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();
}

推荐答案


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

08-19 10:30