-2
<%@ WebHandler Language="C#" Class="dlde" %>
using System;
using System.Web;
public class dlde : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var fileName = @"D:\Error.txt";
var r = context.Response;
r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
r.ContentType = "text/plain";
r.WriteFile(context.Server.MapPath(fileName));
}
public bool IsReusable {
get {
return false;
}
}
我想从指定目录下载从服务器系统的.txt文件...我试图与此代码,但我得到的错误,无效的虚拟path..How得到文件从服务器系统..please帮我...
显示确切的异常及其出现的位置。文件是否存在? – CodeCaster
'@D:\ Error.txt'不是有效的虚拟路径。 – Sambasiva
在我的评论中,我问了几个问题,而不仅仅是那个问题,但无论如何,那么不要'Server.MapPath()'它,因为它已经是一个绝对路径。 – CodeCaster