/downloadtextfile.ashx Secret
Created
April 18, 2016 05:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.IO; | |
using System.Text; | |
namespace Web | |
{ | |
/// <summary> | |
///downloadFile 的摘要描述 | |
/// </summary> | |
public class downloadFile : IHttpHandler | |
{ | |
public void ProcessRequest(HttpContext context) | |
{ | |
this.TestDownloadFile(); | |
} | |
/// <summary> | |
/// 測試下載檔案 | |
/// </summary> | |
private void TestDownloadFile() | |
{ | |
HttpContext.Current.Response.ContentType = "text/plain"; | |
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + string.Format("text-{0}.txt", string.Format("{0:yyyyMMddHHmmss}", DateTime.Today))); | |
HttpContext.Current.Response.Clear(); | |
using (StreamWriter writer = new StreamWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8)) | |
{ | |
writer.Write("This is the content"); | |
} | |
HttpContext.Current.Response.End(); | |
} | |
public bool IsReusable | |
{ | |
get | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment