都1天了,怎么没有人理睬啊,分不够吗?

解决方案 »

  1.   

    如果你的机器上面装了Office,那可以利用Word Application Object来打开RTF文件并另存为HTML或者mhtml格式,这样也能完成RTF到HTML的转换: public void SaveRtfAsHtml(RichTextBox richTextBox,string SaveAsFileName) 

    //保存成一个临时的rtf文件。 
    string tempFileName=System.IO.Path.GetTempFileName(); 
    this.richTextBox1.SaveFile(tempFileName+".rtf",System.Windows.Forms.RichTextBoxStreamType.RichText); object Nothing=System.Reflection.Missing.Value; 
    object srcFileName=tempFileName+".rtf"; 
    object dstFileName=SaveAsFileName; 
    object format=Word.WdSaveFormat.wdFormatHTML; //打开刚才保存的rtf文件 
    Word.Application wordApp=new Word.ApplicationClass(); 
    Word.Document wordDoc=wordApp.Documents.Open(ref srcFileName,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing); //将rtf文件save as成html文件 
    wordDoc.SaveAs(ref dstFileName,ref format,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing); 
    wordDoc.Close(ref Nothing, ref Nothing, ref Nothing); 
    wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); 
    } 上面那个SaveRtfAsHtml函数主要做了这么几件事情: 
    1)把一个richtextbox里面的内容存成一个临时的rtf文件。 
    2)用word application object打开这个临时的rtf文件。 
    3)另存为用户指定路径的一个html文件。 例如,可以这样使用这个函数: 
    SaveRtfAsHtml(this.richTextBox1,@"c:\mydoc.html");