解决方案 »
- ASP.NET 页面数据验证?
- 急急急
- gridview 全选 不刷新页面
- 用ArrayList 得到从数据库中的返回值
- 有没有办法让页面在什么大小的时候都能显示出全部的内容呀
- asp.net TreeView 控件使用问题
- Error HRESULT E_FAIL has been returned from a call to a COM component.
- 自定义服务器控件,类的构造函数在HTML方法下怎么初始化,带参数的?在线waiting
- 招贤榜:有人用过TestDirector7.2吗?其中的树形列表及右键定义控制菜单完美堪称完美,不过不知道是怎么实现的,故来此寻找高人!!
- 文件上传能做到代码和界面分离吗?
- 求助,winwebmail邮件不能发送出去,返回错误!求解!
- 数据查询和table显示问题
<%@ WebHandler Language="C#" Class="FileHandler" %>using System;
using System.Web;using System.Data;
using System.IO;
using System.Text;public class FileHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; string maskId = string.Empty;
if (context.Request.QueryString["ID"] != null)
{
maskId = context.Request.QueryString["ID"].ToString().Trim();
DataTable myDataTable = DBsql.GetDataTable("select * from T_Soft where id =" + maskId);
if (myDataTable.Rows.Count == 1)
{
string filePath = HttpContext.Current.Server.MapPath("~/" + myDataTable.Rows[0]["DownUrl1"].ToString());
if (System.IO.File.Exists(filePath))
{
FileInfo fileInfo = new FileInfo(filePath);
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name));
context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
context.Response.AddHeader("Content-Transfer-Encoding", "binary");
context.Response.ContentType = "application/octet-stream";
context.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
context.Response.WriteFile(fileInfo.FullName);
context.Response.Flush();
context.Response.End();
}
else
{
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "text/html";
context.Response.Write("The file does not exist!");
context.Response.Flush();
context.Response.End();
}
}
else
{
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "text/html";
context.Response.Write("The resource does not exist!");
context.Response.Flush();
context.Response.End();
}
}
}
public bool IsReusable {
get {
return false;
}
}}
http://www.cnblogs.com/insus/articles/2003336.html
网上的效果一个都没有实现~~楼主想过为什么这些代码不行吗?自己可以改动改动吗?我是新手,你有什么好的建议吗?
不需要源代码,你建立一个FTP服务器,用serv-u之类的软件,
软件中配置服务器上提供下载的文件目录。
你原本是http://www.abc.com/aa.txt
就改成 ftp://www.abc.com/aa.txt 即可