<%@ 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文件...我尝试使用此代码,但我收到错误,虚拟路径无效。如何从服务器系统获取文件。 。请帮助我...
答案 0 :(得分:0)
使用"WebClient "
string remoteUri = "http://Yoursite.com/file.txt";
string fileName = @"D:\";
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(remoteUri, fileName);
从MSDN学习命名空间
答案 1 :(得分:0)
string fName = @"D:\Error.txt";
System.IO.FileStream fs = System.IO.File.Open(fName, System.IO.FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.AddHeader("Content-disposition", "attachment;
filename=" + HttpUtility.UrlEncode(fname, System.Text.Encoding.UTF8));
context.Response.ContentType = "text/plain";
context.Response.BinaryWrite(btFile);
答案 2 :(得分:0)
drawDonut(data1, "#pie1", "Chart 1")
...
function drawDonut(data, divchart, chartName) {
...
g.append("text")
.attr("transform", "translate(0,60) scale(.7)")
.attr("class", "caption")
.text(chartName);
}