C# File download 日本語ファイル名 in IE

 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)言語によりエンコードを勝手に判断するらしい。

Posted by / November 29, 2013 / Posted in C#

C# convert Object to List

In C#, you can get List like Object type.
This sample will be help you convert object to List

List<Dictionary<String, Object>> list = null;
if ([ListObject] is IEnumerable) {
    list = new List<Dictionary<String, Object>>();
    var enumerator = ((IEnumerable)[ListObject]).GetEnumerator();
    while (enumerator.MoveNext()) {
        list.Add((Dictionary<String, Object>)enumerator.Current);
    }
}

Posted by / November 29, 2013 / Posted in C#