10 Answers, 1 is accepted
Spans do not have an ID property. The closest thing to an ID is the hash code of the Span, which can be obtained like this:
radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.GetHashCode();
Iva
the Telerik team

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
html
xmlns
=
"http://www.w3.org/1999/xhtml"
><
head
><
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=utf-8"
/><
title
>Untitled</
title
><
style
type
=
"text/css"
>
.p_A215EAA9 { margin: 0px 0px 20px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_2792A6B5 { font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 34.6666679382324px;color: #17365D; }
.p_B0B4BECC { margin: 0px 0px 13.3333330154419px 0px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_79B9C72D { font-family: 'Calibri';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; }
.s_47B2206B
{ font-family: 'Calibri';font-style: Normal;font-weight:
normal;font-size: 16px;color: #0000FF;text-decoration: underline; }
.p_52CCE107 { margin: 0px 0px 13.3333330154419px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_15F27AAB { font-family: 'Calibri';font-style: Normal;font-weight: bold;font-size: 26.6666660308838px;color: #365F91; }
.p_D4BD696B { margin: 0px 0px 0px 20px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_1B36B066
{ font-family: 'Calibri';font-style: Normal;font-weight:
normal;font-size: 16px;color: #000000;background-color: #FFFF00; }
.s_E6FD2046 { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; }
.p_55DBFD74 { margin: 0px 0px 0px 0px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_7D26D8AB { font-family: 'Calibri';font-style: Normal;font-weight: bold;font-size: 18.6666660308838px;color: #365F91; }
.p_9AE926D3
{ margin: 0px 0px 0px 20px;text-align: justify;text-indent:
0pt;padding: 0px 0px 0px 0px;background-color: #FFFFFF; }
.p_D9C3C42D { margin: 32px 0px 0px 0px;text-align: justify;text-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_361E4FF5 { font-family: 'Arial';font-style: Normal;font-weight: normal;font-size: 14.6666669845581px;color: #333333; }
<
body
><
p
class
=
"p_A215EAA9"
><
span
id
=
"ab123456"
class
=
"s_2792A6B5"
>RadRichTextBox for Silverlight and WPF</
span
></
p
><
p
class
=
"p_B0B4BECC"
><
span
id
=
"ab789"
class
=
"s_79B9C72D"
>RadRichTextBox was initially developed in </
span
></
body
></
html
>
"ab123456
" and "ab789"
i want these span id on selection of text using
radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox()
radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan
or anything by which i could get the spanid.
here's my code
private void Window_Loaded(object sender, RoutedEventArgs e)
{
radRichTextBox1.Document = ImportDocx();
}
public RadDocument ImportDocx()
{
RadDocument document = null;
IDocumentFormatProvider provider = new Telerik.Windows.Documents.FormatProviders.Html.HtmlFormatProvider();
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "HTML|*.html";
openDialog.Multiselect = false;
bool? dialogResult = openDialog.ShowDialog();
if (dialogResult == true)
{
FileStream stream = new FileStream(openDialog.FileName.ToString(),FileMode.Open);
document = provider.Import(stream);
}
return document;
}
private void radRichTextBox1_MouseUp(object sender, MouseButtonEventArgs e)
{
string a = radRichTextBox1.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan.Text;
//i am getting text, need span ID
}
Thanks for prompt reply
EDIT: i want to display record from database, and i want to save there record ID too.. so if the user select any of the node(text) its correspond ID would be selected.
Regards
Faheem

i am waiting of your reply, its kinda urgent
Regards
Faheem Khatri
All properties and elements that the format providers do not recognize are lost at the time the document is imported. Since the span's ID is only used to determine the style of the span, it cannot be retrieved at a later point in time. What is more, if you apply some formatting option on a span, it will be split into several others, new style classes will be added and the span's class will change accordingly.
If you need to keep track of parts of the document, you can try using Bookmarks. They are persisted along with their names and provide some methods that will enable you to programmatically detect, select and manipulate them.
Iva
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

can you provide me example of bookmark which saves span id for example in it... and when i click on particular span it returns me the span id. because its difficult to find these kind of example.
The currently available method for what you want would be to preprocess the HTML and replace the id="span_id" attributes with <a name="span_id"> tags. These get imported as bookmarks. Then, after export, the process should be inverted. This pre and post-processing requires that the HTML is a well-formed XHTML document. If that is not the case, then this will not work.
We have no such demo available, but if you explain in greater detail your specific case, then we will be able to assist you further.
All the best,
Ivailo
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Here's a demo on how to do an HTML import converting span ids to anchors and how to extract the text inside the bookmark ranges. Hope it helps.
Best wishes,
Ivailo
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Edit:
Converted the project to WPF, on selection of span can i get the id of that selected span by bookmark (Anchor tag)? using current caret position or anything.
You can enumerate all bookmarks in the document as in the example, using GetAllBookmarks. Then, for each bookmark, you can retrieve the start and end position (shown in the example) and by comparing them with the caret position, you can find the bookmarks which contain the caret position.
Greetings,
Ivailo
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!