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#

iOS7 Safari Html5 Audio Tag bugs

I just find bugs on iPhone5 upgraded with iOS7
Combination of [audio.play + new Audio] is unstable.

//This is sample source.

var audio1=new Audio(“[url of sound’s file]”);



// button’s touchstart event function
/********************
    case1 – play sounds well
********************/
function playButton(){
    audio1.play();
}

/********************
    case2 – can’t play sounds
********************/
function playButton(){
    audio1.play();
    var audio2 = new Audio(“[url of sound’s file]”);
}

/********************
    case1 – can’t play sounds well on 4G,3G mode
********************/
function playButton(){
    audio1.play();
    setTimeout(function(){
        var audio2 = new Audio(“[url of sound’s file]”);
    },500);
}

Twitter Button – Resize with javascript

<div id=”sns_twitter”>
<a href=”https://twitter.com/share”
    class=”twitter-share-button”
    data-url=”[your site address]”
    data-text=”[your site description]”
    data-hashtags=”[your site title]”>Tweet</a>
<script type=”text/javascript”>
    ! function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0],
        p = /^http:/.test(d.location) ? ‘http’ : ‘https’;
        if (!d.getElementById(id)) {
            js = d.createElement(s);
            js.id = id;
            js.src = p + ‘://platform.twitter.com/widgets.js’;
            fjs.parentNode.insertBefore(js, fjs);
        }
    }(document, ‘script’, ‘twitter-wjs’);
</script>
</div>

// get twitter button(iframe) size
var snsTwitterIframeWidth = $(“#sns_twitter > iframe”).css(“width”);
// trim “px”
snsTwitterIframeWidth = parseInt(snsTwitterIframeWidth.substring(0, snsTwitterIframeWidth.length – 2));
// minus 34px on button(iframe) size (english only)
var snsTwitterWidth = snsTwitterIframeWidth – 34);
// resize twitter button wrapper
$(“#sns_twitter”).css(“width”, snsTwitterWidth + “px”);

// 1.wrap twitter button with div(sns_twitter here)
// 2.set style div overflow:hidden
// 3.resize your div size