[英]Getting error as not a valid virtual path while downloading file in C # asp.net
I have written a piece of code for downloading the file from the server. 我已经编写了一段代码,用于从服务器下载文件。 So when I download it, the file gets downloaded properly.
因此,当我下载它时,文件将正确下载。 But when I Open the document, it shows me error as.
但是当我打开文档时,它显示为错误。
Failed to load particular document.
无法加载特定文档。
Also while debugging I get error as. 另外在调试时我得到错误。
'https:/NVMBD1BKH150V02.IN.RIL.COM/MWSiteSurveyDoc/I-KA-ANKL-ENB-0012_C2/180.jpg' is not a valid virtual path.
'https:/NVMBD1BKH150V02.IN.RIL.COM/MWSiteSurveyDoc/I-KA-ANKL-ENB-0012_C2/180.jpg'不是有效的虚拟路径。
when I open the URL in browser, the file is opened properly. 当我在浏览器中打开URL时,文件已正确打开。
Here is my code below 这是我的下面的代码
protected void lnkDownload_Click(object sender, EventArgs e)
{
try
{
string FulfilePath = (sender as LinkButton).CommandArgument;
string[] filePath = FulfilePath.Split('\\');
string path = @"" + ConfigurationManager.AppSettings["NASSServerPath_MW_Feasibility_Download"].ToString() + "/" + filePath[7] + "/" + filePath[8];
// Response.ContentType = ContentType;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(path));
Response.TransmitFile(path);
Response.End();
}
catch (Exception ex)
{
// objCom.ErrorLog(ex.GetType().ToString(), ex.Message, "Download Files", Session["UserName"].ToString());
}
}
HttpResponse.Transmit takes a server physical path to a file as a parameter. HttpResponse.Transmit将服务器到文件的物理路径作为参数。 Seems you are trying to pass a remote URI instead, and there is also a typo: a slash is missing in http:// prefix.
似乎您正尝试传递远程URI,并且还有一个错字: http://前缀中缺少斜杠。
You either need to provide a local path to the TransmitFile method or redirect the request to the URI 您要么需要提供TransmitFile方法的本地路径,要么将请求重定向到URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.