易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET 文件下载

下载页面:
 <a href="download.ashx?url=<%=Server.UrlEncode("说明.txt")%>">下载</a>
------------------------------------------------------------------------------
download.ashx
<%@ WebHandler Language="C#" Class="download" %>
using System;
using System.Web;
public class download : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        string url = HttpContext.Current.Server.UrlDecode(context.Request.QueryString["url"]);
        downloadfile(url);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    public void downloadfile(string s_fileName)
    {
       HttpContext.Current.Response.ContentType = "application/ms-download";
       string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName;
       System.IO.FileInfo file = new System.IO.FileInfo(s_path);
       HttpContext.Current.Response.Clear();
       HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
       HttpContext.Current.Response.Charset = "utf-8";
       HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
       HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
       HttpContext.Current.Response.WriteFile(file.FullName);
  


相关文档:

关于ASP.NET控件在编译时找不到的解决方案

     本人开发ASP.NET已有两年多了。谈起ASP.NET真是让我欢喜让我忧。昨天又出现了那个奇怪的问题,就是在页面完全写好后,重新生成时报:XXX(页面名)不包含(XXX)的定义。在CS文件下是可以用 this.xxx 写出来的,页面上也没问题。在解决方案中重新生成页又可以,重新生成网站就会报这个错误。将this.XXX ......

ASP.NET中防止页面多次提交的代码实现

1.   
此处提供的代码用来实现当asp.net
页面中的某个Button
被点击后disable
掉该页面中所有的Button
,从而防止提交延时导致的多次提交。基于之前的onceclickbutton
脚本.
//ASP.NET
中防止页面多次提交的代码:javascript< script
language="javascript"> < !-- function dis ......

asp.net 程序动态添加gridview

前台:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   
   
     ......

Asp.net页面传值方法及实用技巧

一. 使用QueryString变量
    QueryString是一种非常简单也是使用比较多的一种传值方式,但是它将传递的值显示在浏览器的地址栏中,如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法。
         Response.Redirect( "target.aspx?param1=hello& ......

ASP.NET FileUpload应用实例

Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号