I have a rich textbox and I want to use a hyperlink on it, so when the user clicks it, the website link or local file is opened. In my last question, I said that link click event does not fire properly, this problem is solved, but now I have another problem.
I try to create a hyperlink and my characters are in utf8 (Farsi/arabic). But for example when I write this text
سلام چطوری خوبم خوبی؟ چه خبر؟
and choose "چه" as link text and "C:\Users\sadegh\Desktop\16.txt" as url, the result is:
سلام چطوری خوبم خوبی؟ ?? file://C:/Users/sadegh/Desktop/16.txtخبر؟
How can I fix this? My code is:
private void AddLinkBtn_Click(object sender, EventArgs e)
{
string url = null;
OpenFileDialog openFileDialog = new OpenFileDialog();
//openFileDialog.Filter = "Image Files (*.jpg;*.jpeg,*.png)|*.JPG;*.JPEG;*.PNG";
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
url = openFileDialog.FileName;
}
if (!string.IsNullOrEmpty(url))
{
string linkText = TextBoxDefinition.SelectedText;
byte[] bytes = Encoding.UTF8.GetBytes(linkText);
linkText = Encoding.UTF8.GetString(bytes);
TextBoxDefinition.SelectedRtf = @"{\rtf1\utf8\field{\*\fldinst HYPERLINK ""file://" + url.Replace("\\", "/") + @""" }{\fldrslt" + linkText + "}}";
}
}
UPDATE: I forget said. I use .NET framework 4.5.