自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。

2010年5月26日水曜日

Asp.Netファイルダウンロード

Asp.Netのファイルダウンロード処理のサンプルソースをメモします。

VB.Net

Private Sub DownloadFile(ByVal pstrContent As String)
    Response.Clear()
    Response.ContentType = "application/octet-stream"
    Response.Charset = "Shift_JIS"
    Response.ContentEncoding = Encoding.Default
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMdd") + ".csv"))
    Response.Write(pstrContent)
    'Response.WriteFile(strFilePath)
    'Response.BinaryWrite(objFileIO.IFileByte(strFilePath))
    Response.Flush()
    Response.Close()
End Sub

レスポンス内容タイプ:
"application/msword"
"application/vnd.ms-excel"
"application/pdf"
"application/vnd.ms-powerpoint"
"image/jpeg"
"image/bmp"
"image/gif"
"application/zip"
"text/plain"
"application/octet-stream"

0 件のコメント:

コメントを投稿

ホームページ