public void FileCreate(string sdata, string filename)
        {
            if (sdata.Length > 0)
            {
                Response.Clear();
                Response.ContentType = "application/octet-stream";
                Response.ContentType = "text/plain";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
                Response.Charset = "UTF-8";
                Response.Write(sdata);
                Response.Flush();
                Response.End();
            }
            
        }

解决方案 »

  1.   

            public void FileCreate(string sdata, string filename) 
            { 
                if (sdata.Length > 0) 
                { 
                    Response.Clear(); 
                    Response.ContentType = "text/plain"; 
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); 
                    Response.Charset = "UTF-8"; 
                    Response.Write(sdata); 
                    Response.Flush(); 
                    Response.End(); 
                } 
                
            } 
    提示错误
      

  2.   

    ASP.NET 没有权限操作客户端的
    所以还是把你的字符串保存为一个txt,然后点击链接或者其他的办法查看
    然后另存吧
      

  3.   

    ASP.NET 没有权限操作客户端的
    所以还是把你的字符串保存为一个txt,然后点击链接或者其他的办法查看
    然后另存吧
      

  4.   

    生成txt很容易,但要直接扔给客户端的话需要客户端安装ActiveX吧
      

  5.   

    我先保存字符串为一个txt文件,然后下载该文件,依然提示错误,为什么呢?
            public void FileCreate(string sdata, string filename)
            {
                if (sdata.Length > 0)
                {
                    FileStream fs = new FileStream("c:\\" + filename, FileMode.Create, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs);
                    sw.Write(sdata);
                    sw.Flush();
                    sw.Close();
                    fs.Close();                FileInfo file = new FileInfo("c:\\" + filename);
                    Response.Clear();
                    Response.ContentType = "application/octet-stream";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.Charset = "UTF-8";
                    Response.WriteFile(file.FullName);
                    Response.End();
                }
                
            }
      

  6.   

    你这段代码是在服务器端用的,还是在客户端用的?我先保存字符串为一个txt文件,    ----像是服务器端?
    然后下载该文件,                -----像是客户端?
    依然提示错误,为什么呢? 
      

  7.   

    Sys.WebForms.PageRequestManagerParserErrorException:The message received from the server could not be parsed.Common causes for this error are when the response is modified by calls to Response.Write(),response filters,HttpModules,or server trace is enabled.
    Details:Error parsing near '....'
      

  8.   

    在iis 添加个txt  MIME类型 
    txt
    .txt