Try Catch XML Import for RadRichText

4 posts, 0 answers
  1. Cuthahotha
    Cuthahotha avatar
    81 posts
    Member since:
    Sep 2008

    Posted 22 Nov 2010 Link to this post

    The following code doesn't drop into the catch block on an error in the xml.  If I have a string "Test" in my content, the code errors on the italic line below with this error.   And will not drop in to the catch block. 

    {System.Windows.Markup.XamlParseException: illegal xml character [Line: 1 Position: 2]
       at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers, Boolean expandTemplatesDuringParse)
       at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)
       at System.Windows.Markup.XamlReader.Load(String xaml)
       at Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Import(String input)
       at Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Import(Stream input)
       at ICollegeLifeSLClient.Classes.RadDocSupport.ImportXaml(String content)}

    public RadDocument ImportXaml(string content)
              IDocumentFormatProvider provider = new XamlFormatProvider();
              RadDocument document;
              using (MemoryStream stream = new MemoryStream())
                  StreamWriter writer = new StreamWriter(stream);
                  stream.Seek(0, SeekOrigin.Begin);
                  document = provider.Import(stream);
              return document;
          catch (Exception ex)
              string message = ex.Message;
              return null;
  2. Ivailo Karamanolev
    Ivailo Karamanolev avatar
    276 posts

    Posted 23 Nov 2010 Link to this post

    Hi Cuthahotha,

    I have rewritten the method you use with the much more concise Import(string) methods and couldn't reproduce the issue, please try that. If your issues persist, make sure you have referenced the latest versions of the binaries, and if still - contact us, preferably with a demo project, for further assistance. Here's the modified version of the method:
    private RadDocument Import(string str)
            return new XamlFormatProvider().Import(str);
        catch (Exception ex)
            return null;

    Best wishes,
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. caleb
    caleb avatar
    32 posts
    Member since:
    Sep 2011

    Posted 04 Aug 2016 in reply to Ivailo Karamanolev Link to this post

    Hello there,


    I was able to reproduce this. 

    Input (m.Text):



    if (m.Text.Length > 100 && !m.Text.Substring(0, 100).Contains(" "))
        var document = new RadDocument();
        var bytes = Convert.FromBase64String(m.Text);
            document = new XamlFormatProvider().Import(bytes);
            //Now dump out the rich text format and save
            var customFormatProvider = new TxtFormatProvider();
            var txtText = customFormatProvider.Export(document);
            txtText = g.ReplaceQuotes(txtText);
            m.TXTText = txtText;
            DatabaseConnection.Update(m); //Do not update if an error has occured
        catch (Exception err)
            LogHelper.CreateLog("CleanupData.cs: Populating TXTText", err);
  4. Todor
    Todor avatar
    168 posts

    Posted 08 Aug 2016 Link to this post

    Hello Caleb,

    Thank you for the sent code-snippet.

    I've tried to convert the encoded Base64 string to a string which describes a valid XML document, but to no avail. Indeed, this is the reason the document cannot be imported. Can you share how the RadDocument instance is exported and the result string is achieved?

    Looking forward to your reply.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top