string filename = “test.xls”;
string filePath = “c:\text.xls”;
FileStream sourceFile = new FileStream(filePath, FileMode.Open);
float FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
// 日本語ファイル名対応(japanese filename support)
HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding(“shift_jis”);
HttpContext.Current.Response.AddHeader(“Content-Disposition”, “attachment; filename=” + filename);
HttpContext.Current.Response.ContentType = “application/octet-stream”;
HttpContext.Current.Response.BinaryWrite(getContent);
HttpContext.Current.Response.End();
// IEでは.NET利用し、システム(OS)言語によりエンコードを勝手に判断するらしい。