This is a migrated thread and some comments may be shown as answers.

How to export bookmarks

7 Answers 73 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Stergios
Top achievements
Rank 1
Stergios asked on 30 Nov 2012, 07:22 PM
Hello,

Is it possible to save or export a list of bookmarks (eg in isolatedstorage or file) and reload them the next time that the same document is loaded?

7 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 05 Dec 2012, 01:31 PM
Hi Stergios,
Bookmarks are persisted on exporting using our format providers to the following formats:
  • XAML
  • DOCX
  • RTF
  • HTML
Importing the exported file back in the editor will reload these bookmarks and you can choose the format provider that best fits your scenario.

Please do not hesitate to get back to us if you have other questions.
 
Kind regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Stergios
Top achievements
Rank 1
answered on 05 Dec 2012, 04:58 PM
Thank you for the reply.

The problem is that in my scenario I parse digitally signed xml files that (after verification) are displayed in a read-only RadRichTextBox control. The files are retreived dynamically from a web server and I don't control the content, while the concept is that the end-user can add bookmarks or comments that should be saved locally and reloaded on demand.

From your post I understand that if I will use an exporting format to store the bookmarks, then I have to parse the exported content, retreive the bookmarks and assign them to the document source.

Actually I was thinking of serializing and saving a bookmarks collection in the IsolatedStorage, attaching the source xml file reference and its signature (to verify that the bookmarks are still valid). Is it possible?

Regards,

Stergios
0
Petya
Telerik team
answered on 07 Dec 2012, 03:38 PM
Hi Stergios,

I am having a hard time understanding your scenario.

What I should probably say is that the bookmarks that are part of RadDocument's structure change the document - they add a BookmarkRangeStart and BookmarkRangeEnd inlines at the beginning and the end of the bookmarked text. That said and since you want your documents to be read only, I am not sure if that approach will be a suitable for your case.

Can you please elaborate a bit on your scenario? When you say you are thinking of serializing a bookmark collection, do you mean some other implementation and not RadDocument's bookmarks?

I am looking forward to your reply regarding the approach you wish to implement in bookmarking the contents of your document.


All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Stergios
Top achievements
Rank 1
answered on 07 Dec 2012, 06:37 PM
Hello,

I was thinking of something like retreiving all the bookmarks from a document:

IEnumerable

 

 

<BookmarkRangeStart> allBookmarks= radRichTextBox.Document.GetAllBookmarks();

and then send the allBookmarks to IsolatedStorage or a database.

My question is if after reloading the same document I can programmatically re-add the bookmarks.

 

0
Petya
Telerik team
answered on 12 Dec 2012, 09:14 AM
Hi Stergios,
As I said, bookmarks affect the contents of the document and cannot be added when the document is read-only. They are also persisted on exporting, so if choose that approach you will not need to keep them in a separate data-entry.
On the other hand, if you decide to serialize the bookmarks separately and remove them using the DeleteBookmark method, that will not work. Ranges are associated with the document instance and once you unload the document the BookmarkRangeStart instances will become invalid.
You can implement some custom bookmarking mechanism using the HierarchicalIndex class and its methods. The indexes are used to identify all positions in the document and can be easily persisted as int array, and they are not changed when exporting and importing the document back (when the document is read-only). You can create logic that will keep the indices of your custom bookmark's start and end and keep them in a separate data entry or in Isolated Storage.

I hope this helps!

 
Greetings,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Stergios
Top achievements
Rank 1
answered on 31 Dec 2012, 09:43 AM
Thank you Petya,

Could you please send me some resources related to the usage of the HierarchicalIndex class?

In the online documentation I found only this link: http://www.telerik.com/help/silverlight/t_telerik_windows_documents_hierarchicalindex.html
but is not very helpfull.

Regards,

Stergios
0
Accepted
Boby
Telerik team
answered on 02 Jan 2013, 11:33 AM
Hello Stergios,
Using HierarchicalIndex is advanced technique which, unfortunately, is not covered by help article for now. Please see the example below showing how to save a DocumentPosition (document's caret position in the sample) to a int array - format that can be serialized easily:

private int[] hierachicalIndexArray;
private int currentPositionInSpan;
   
private void buttonSave_Click(object sender, RoutedEventArgs e)
{
    this.hierachicalIndexArray = HierarchicalIndex.GetHierarchicalIndexByBox(this.radRichTextBox.Document.CaretPosition.GetCurrentInlineBox()).GetIndexArray();
    this.currentPositionInSpan = this.radRichTextBox.Document.CaretPosition.GetCurrentPositionInSpan();
   
    this.radRichTextBox.Focus();
}
   
private void buttonRestore_Click(object sender, RoutedEventArgs e)
{
    HierarchicalIndex index = new HierarchicalIndex(hierachicalIndexArray);
    InlineLayoutBox inlineLayoutBox = (InlineLayoutBox)HierarchicalIndex.GetBoxByHierarchicalIndex(this.radRichTextBox.Document.DocumentLayoutBox, index);
    this.radRichTextBox.Document.CaretPosition.MoveToInline(inlineLayoutBox, this.currentPositionInSpan);
   
    this.radRichTextBox.Focus();
}
This would work assuming the document is read-only, i.e. the document structure isn't changed between the moments of position's saving and position's restoration.

Greetings,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Stergios
Top achievements
Rank 1
Answers by
Petya
Telerik team
Stergios
Top achievements
Rank 1
Boby
Telerik team
Share this question
or