csv ファイルは既に /Exports/test.csv として保存しています。ユーザーがボタンクリックでファイルをダウンロードできるようにしたい。そのコードのハンドラーを作成しました:
<%@ WebHandler Language="C#" Class="Downloadfile" %>
using System;
using System.Web;
using System.Net;
public class Downloadfile : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
context.Response.ContentType = "text/csv";
context.Response.AddHeader("Content-Disposition",
"attachment; filename=" + context.Request.QueryString["file"]);
context.Response.End();
}
public bool IsReusable
{
get
{
return true;
}
}
}
上記のコードはファイルをダウンロードしますが、空です。そのコンテンツを含むcsvファイルをダウンロードしたいだけです。