C#form 양식을 통해 텍스트 파일 다운로드

2183 단어 form
 public void DownLoadConfigFile(string name)
        {
            // 
            var data = _service.ReadFileStr(_configureFilePath + name);
            MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(data));
            string filename = HttpUtility.UrlEncode(name);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AddHeader("Content-Disposition", ("attachment;filename=" + filename));
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentType = "text/json";
            HttpContext.Current.Response.BinaryWrite(ms.ToArray());
            HttpContext.Current.Response.Flush();
        }

참조:
ajax:
$("#myform").attr("action", "/AjaxSwitchConfigInfo/DownLoadConfigFile.cspx?name=" + $("#filename").val());
$("#myform").submit();

좋은 웹페이지 즐겨찾기