Adding pages on the fly to the radbook

10 posts, 0 answers
  1. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 17 Nov 2010 Link to this post

    Hi,

    Is it possible to setup a polling mechanism so that my RadBook implementation can poll a directory on the site, and if any new files are added to this dir, they can be added to the radbook?

    I know a polling mechanism isn't RadBook-specific and can be coded, but can I add pages on the fly (HTML)?

    Also, can I embed the Silverlight report viewer in the RadBook?

    Thanks
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 18 Nov 2010 Link to this post

    Hello G S S,

    Adding pages (RadBookItem) is supported and is the same as adding an item in any other ItemsControl.
    Also, using a report viewer in the book is a supported scenario. Here is an interesting article on the subject.

    Using Telerik Report WCF Service (or how to display reports in RadBook)

    Also, you can take a look at this integration example "RadBook and RadRichTextBox".

    Regards,
    Kiril Stanoev
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 13 Feb 2011 Link to this post

    Hi,

    To add to my original question, what I want/need to do is bind 15-20 HTML paes into the RadBook. These pages are stored in the same directory, so I need to loop over each page and bind it, eg:

    foreach (File file in Directory.GetDirectory(DirectoryPath))
    {
      radBook1.BindToBook(file);
    }

    This is not valid C#, but is the pseudo code of what I need to do. Also (And this is a Silverlight-specific question). What would be the way to do this?

    Thanks
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 16 Feb 2011 Link to this post

    Hello G S S,

    Please take a look at the attachments in this forum thread. I believe they will be useful to your scenario.

    Best wishes,
    Kiril Stanoev
    the Telerik team
  6. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 16 Feb 2011 Link to this post

    Hi,

    That's a good find, thank you! The only issue with that is:

                  this.book.ItemsSource = bindingSource;

    bindingSource has one property - Document - which is set to one HtmlDocument (in the code of where I got the snippet above from). However, I want to add >1 page to the items source. How can I do this? I'd expect to use a collection here?


    Thanks     
  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 22 Feb 2011 Link to this post

    Hello G S S,
    RadDocumentBindingSource is designed for showing one document in RadBook. If you have multiple documents, you can either merge them in one, or use custom DataTemplate for RadBook's pages containing RadRichTextBox bound to your HTML documents. For binding RadRichTextBox, take a look at this article.

    Kind regards,
    Boby
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  8. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 23 Feb 2011 Link to this post

    Thanks for this help.

    I have made a solution (Silverlight Application) which has a radbook and binds a single .docx. I've pretty much copied the example solution on the Silverlight Demos. My XAML is as follows:

    <P><UserControl x:Class="CodeQualityBookApp.MainPage"<BR>    
    xmlns="<A 
    xmlns:x="<A 
    xmlns:d="<A 
    xmlns:mc="<A 
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
    xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Documents" 
    mc:Ignorable="d"<BR>    d:DesignHeight="300" 
    d:DesignWidth="400"></P>
    <P>    
    <UserControl.Resources><BR> <BR>        
    <Controls:DocumentViewManager 
    x:Name="viewManager"></Controls:DocumentViewManager></P>
    <P><BR>        <Grid x:Name="LayoutRoot" 
    Background="White"></P>
    <P>     <telerik:RadBook Name="book" 
    RightPageIndex="1"><BR>            
    <telerik:RadBookItem><BR>                
    <BR>            
    </telerik:RadBookItem><BR>        
    </telerik:RadBook><BR>    
    </Grid><BR>       
    </UserControl.Resources></UserControl></P>

     
    The codebehind C# is:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Documents;
    using Telerik.Windows.Documents.FormatProviders;
    using Telerik.Windows.Documents.Layout;
    using Telerik.Windows.Documents.Model;
      
    namespace CodeQualityBookApp
    {
        public partial class MainPage : UserControl
        {
      
            private RadDocumentBindingSource bindingSource = new RadDocumentBindingSource();
      
      
            public MainPage()
            {
                InitializeComponent();
                 UserControl_Loaded(this, new RoutedEventArgs());
            }
      
      
      
            public void LoadDocument(Stream stream, string extension)
            {
      
                RadDocument doc;
      
                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);
                if (provider != null)
                {
                    doc = provider.Import(stream);
                }
      
                else
                {
                    MessageBox.Show("Unknown format.");
                    return;
                }
      
                doc.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                doc.Arrange(new RectangleF(PointF.Empty, doc.DesiredSize));
      
                doc.LayoutMode = DocumentLayoutMode.Paged;
      
                doc.DefaultPageLayoutSettings.Width = 320 / 0.7F;
                doc.DefaultPageLayoutSettings.Height = 390 / 0.7F;
                doc.SectionDefaultPageMargin = new Padding(55);
                doc.Sections.First.PageMargin = new Padding(55);
      
                doc.UpdateLayout();
      
                this.book.RightPageIndex = 0;
              
      
                this.viewManager.Document = doc;
                bindingSource.Document = doc;
            }
      
                private Uri GetResourceUri(string resource)
            {
                AssemblyName assemblyName = new AssemblyName(this.GetType().Assembly.FullName);
                string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
                Uri resourceUri = new Uri(resourcePath, UriKind.Relative);
      
                return resourceUri;
            }
      
      
      
            private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                using (Stream stream = Application.GetResourceStream(this.GetResourceUri("Build Server conventions.docx")).Stream)
                {
                    this.LoadDocument(stream, ".docx");
                }
                this.book.ItemsSource = bindingSource;
            }
      
        }
    }

    The referenced file has been added to the project, and appears inside. When I view this page in my browser, the Silverlight loader indicator keeps spinning (with no progress %).


    Thanks
  9. Boby
    Admin
    Boby avatar
    595 posts

    Posted 01 Mar 2011 Link to this post

    Hello G S S,

    The behavior you observed is most probably because the application crashes when loading. You can try to debug it and check where the exception is thrown. Unfortunately we cannot determine the reason for this by the code provided.

    Best wishes,
    Boby
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  10. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 01 Mar 2011 Link to this post

    Hi,

    Thanks, I will do that. However, is the code below correct for what I am trying to do?


    Thanks   
  11. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 04 Mar 2011 Link to this post

    Hello G S S,

    There is nothing particularly wrong with your code/approach. If you keep experiencing issues, please try to debug the application and see what the exception or problem is. If that doesn't help either, we'll be able to assist you further if you send us a small demo project which exhibits this wrong behavior.

    All the best,
    Ivailo
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top
DevCraft banner