C#使用库
这是一个相当菜鸟的问题,所以请耐心等待。
我正在创建一个允许发送电子邮件的软件。
发送部分工作完美。
问题在于电子邮件正文以 rtf 格式保存在 mssql 数据库中。当我检索 rtf(存储在字符串中)时,电子邮件以纯文本形式发送,而 rtf 代码被视为文本。
我需要将 rtf 文本转换为 html,并且我正在尝试使用此库: http:// /www.codeproject.com/KB/recipes/RtfConverter.aspx
问题是我不知道如何使用它。当我提取库时,有数百个文件。我设法通过在 biin/release 文件夹中找到的 dll 添加 rtf.interpreter、rtf.parser、rtf.converter.html 作为参考。但现在我不知道下一步该怎么走。
我如何在我的项目中使用它来将 rtf 字符串转换为 html?
谁能指导我完成这个?谢谢。
This is quite a noob question, so please bear with me.
I am creating a software which allows email to be sent.
The sending part works flawlessly.
The problem is that the body of the email is saved in a mssql database in rtf format. When I retrieve the rtf (stored in a string), the email is sent as plain text, with the rtf code considered as text.
I need to convert the rtf text to html and I am trying to use this library: http://www.codeproject.com/KB/recipes/RtfConverter.aspx
Thing is I have no clue on how to use it. When I extract the library there are hundreds of files. I managed to add as reference rtf.interpreter, rtf.parser, rtf.converter.html through dlls found in the biin/release folder. But now I dont know the next step.
How can I use this in my project to convert the rtf string to html?
Can anyone guide me through this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里是一个最小的示例:
另请查看包含的示例 RtfWinForms (winForms) 或 RtfWindows (WPF)。
Here a minimal sample:
Check out also the included samples RtfWinForms (winForms) or RtfWindows (WPF).
从这篇文章来看,我相信您正在寻找的类是
RtfHtmlConverter
。最简单的方法是将所有 .dll 文件从 Release 文件夹复制到项目内的文件夹中(您也可以将所有其他依赖项放在这里)。然后,右键单击项目中的
References
文件夹(在 VS 解决方案资源管理器中),然后(当对话框打开时)使用“浏览”来查找适当的程序集。然后,您可以使用本文中提供的示例将 RTF 输入流转换为 HTML 字符串:
取自 您指定的文章,全部归功于作者(尽管稍加修改以返回值,而不是将其打印到控制台):
您可以添加接受字符串的重载:
您还需要添加在源文件的开头添加几个
using
子句,以包含必要的命名空间:From looking at the article, I believe the class you are looking for is
RtfHtmlConverter
.The easiest way would be to copy all .dll files from the Release folder into a folder inside your project (you can put all other dependencies here also). Then, right click the
References
folder in your project (in VS Solution Explorer), and (when the dialog opens) use "Browse" to find appropriate assemblies.Then, you can use the example provided in the article to convert an RTF input stream to a HTML string:
Taken from the article you specified, all credits to the author (although slightly modified to return the value, instead of printing it to console):
You can add an overload which accepts a string:
You will also need to add several
using
clauses to the beginning of your source file, to include the necessary namespaces: