请教 用什么方法能把有中文字符的.htm文档的真个内容以sting形式读出

解决方案 »

  1.   

    /// <summary>
    /// 使用指定的编码方式,文件路径读取一个文本类型文件,返回这个文件的全部内容
    /// </summary>
    /// <param name="fileName">当前要读取的文件路径</param>
    /// <param name="encode">采用何种编码方式读取当前文件</param>
    /// <param name="flag">标识路径是否从网站的根目录开始,true:根目录开始</param>
    /// <returns>返回值是一个字符串表示当前文件的全部内容</returns>
    public static string ReadHtmlFile(string fileName,=System.Text.Encoding encode,bool flag)
    {
         try
         {
    //System.Text.Encoding code1=System.Text.Encoding.GetEncoding("gb2312");
    string htmlText="";

    if(flag==true)
    {
       fileName="~/"+fileName;
    } StreamReader reader=new StreamReader(System.Web.HttpContext.Current.Server.MapPath(fileName),encode);
    htmlText=reader.ReadToEnd();
    reader.Close(); return htmlText;
         }
         catch(Exception e)
        {
    HttpContext.Current.Response.Write(e.Message); 
    HttpContext.Current.Response.End(); 
    return "";
        }
    }
      

  2.   

    不好意思参数里面多加了一个等号
    ,=System.Text.Encoding encode
      

  3.   

    换一下编码,下面几个分别试一下
    System.Text.Encoding.Default
    System.Text.Encoding.ASCII
    System.Text.Encoding.UTF8