[英]Could not find file - “Content-Disposition” in C#
I have implemented Web file manager in my application. 我已经在我的应用程序中实现了Web文件管理器。 It shows the files from the FTP server. 它显示了来自FTP服务器的文件。 When i try to download the file by clicking on the file i'm getting the following error. 当我尝试通过单击文件下载文件时 ,出现以下错误。 Getting the error during WriteFile
line getting executed. 在执行WriteFile
行期间获取错误。
Error: 错误:
Could not find file 'C:\\Users\\ ####\\Desktop\\SeekDotNetFileManager\\AdminMaster.master.cs'. 找不到文件'C:\\ Users \\ #### \\ Desktop \\ SeekDotNetFileManager \\ AdminMaster.master.cs'。
//Code: //码:
Response.AddHeader("Content-Disposition", "attachment; filename=" + lnkName.Text.Trim());
Response.WriteFile(lnkName.Text);
Response.End();
In the lnkName.Text.Trim
the name of the file will be set. 在lnkName.Text.Trim
中,将设置文件的名称。 Eg: AdminMaster.master.cs 例如:AdminMaster.master.cs
Where i'm wrong? 我哪里错了?
Got a Solution: 有解决方案:
//Code //码
string filename = 'Get the full path of file'; //something like /httpdocs/Images/button.gif
string strURL = "http://www.servername.com/";
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
byte[] data = req.DownloadData(strURL);
response.BinaryWrite(data);
response.End();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.