怎么样一个页面存为txt文件,就像在浏览器中,"文件"-"别存为",选txt文件的那种.

解决方案 »

  1.   

    SaveFileDialog~~ 然后将文件读成数据流byte[],写进文件,保存为.txt即可~~ 
      

  2.   


    using System.IO; 
    //写 string time = System.DateTime.Now.ToShortTimeString(); 
    string text = TextBox1.Text; 
    string sss = System.DateTime.Now.ToShortDateString()+".txt"; 
    //指定路径 
    sss = "d:\\"+sss; 
    //如果文件a.txt存在就打开,不存在就新建 .append 是追加写 
    FileStream fst = new FileStream(sss,FileMode.Append); 
    //写数据到a.txt格式 
    StreamWriter swt = new StreamWriter(fst,System.Text.Encoding.GetEncoding("utf-8")); 
    //写入 
    swt.WriteLine(time+'\r'+"写"+text); 
    swt.Close(); 
    fst.Close(); 
    //读 string ss = System.DateTime.Now.ToShortDateString()+".txt"; 
    ss ="d:\\"+ss; 
    //FileStream fs = new FileStream(sss, 
    try 

    StreamReader srt = new StreamReader(ss,Convert.ToBoolean(FileMode.Open)); 
    //存在 
    TextBox2.Text = srt.ReadToEnd(); srt.Close(); } 
    catch(FileNotFoundException ee) 

    TextBox2.Text = ee.ToString(); 
    }
      

  3.   

    页面 查看源代码 copy to txt