PDA

View Full Version : مشکل در تبدیل استایل RichtextBox به کد HTML



benstiler1994
پنج شنبه 12 آبان 1390, 17:04 عصر
من برای تبدیل استایل تکست RichTextBox به HTML Code هیچ کدی پیدا نکردم. من می خوام یه برنامه ایمیل سندر بسازم که باهاش بشه با استایل ایمیل فرستاد مثلا یک تکستی رو Bold می کنم یا رنگش می کنم، وقتی که سند می کنم به ایمیل می بینم که هیچ کدوم از این استایل ها اعمال نشده باید حتما HTML باشه.

خیلی لنگم منو راهنمایی کنید. :افسرده:

pooria_googooli
پنج شنبه 12 آبان 1390, 22:49 عصر
دوست عزیز با این تابع میتونی تکست را به اچ تی ام ال تبدیل کنی :
public string parsetext(string text, bool allow)
{
//Create a StringBuilder object from the string input
//parameter
StringBuilder sb = new StringBuilder(text);
//Replace all double white spaces with a single white space
//and  
sb.Replace(" ", "  ");
//Check if HTML tags are not allowed
if (!allow)
{
//Convert the brackets into HTML equivalents
sb.Replace("<", "&lt;");
sb.Replace(">", "&gt;");
//Convert the double quote
sb.Replace("\"", "&quot;");
}
//Create a StringReader from the processed string of
//the StringBuilder
StringReader sr = new StringReader(sb.ToString());
StringWriter sw = new StringWriter();
//Loop while next character exists
while (sr.Peek() > -1)
{
//Read a line from the string and store it to a temp
//variable
string temp = sr.ReadLine();
//write the string with the HTML break tag
//Note here write method writes to a Internal StringBuilder
//object created automatically
sw.Write(temp + "<br>");
}
//Return the final processed text
return sw.GetStringBuilder().ToString();
}