Completed
Last Updated: 13 Mar 2019 16:21 by ADMIN
Release 2018.3.1016
ADMIN
Hristo
Created on: 09 Apr 2018 11:54
Category: GridView
Type: Bug Report
1
FIX. RadGridView - ArgumentException is thrown when exporting characters not supported in XML
How to reproduce: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        ThemeResolutionService.AllowAnimations = false;
        this.radGridView1.DataSource = this.GetData();
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Rows.Add(1, "\u0002x09");
        for (int i = 1; i < 10; i++)
        {
            dt.Rows.Add(i, "name");
        }

        return dt;
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
        spreadExporter.FileExportMode = FileExportMode.CreateOrOverrideFile;
        SpreadExportRenderer exportRenderer = new SpreadExportRenderer();
        spreadExporter.RunExport(@"..\..\exported-file.xlsx", exportRenderer);
    }
}

ArgumentException with clarification similar to  "'\u001f', hexadecimal value 0x1F, is an invalid character." is thrown when trying to export document containing characters which are not supported in XML document - such as some control characters like 0x00, 0x1F, 0x1B, etc. Such characters are described in the XML specification here: https://www.w3.org/TR/xml/#charsets.

Although the escaped strings are not supported (see  https://feedback.telerik.com/Project/184/Feedback/Details/190228 ), the library could prevent the exception and export the document successfully by skipping such characters.

Workaround: remove such characters before the export. Check the following StackOverflow answer for some ideas on code for replacing the characters: http://stackoverflow.com/a/14323524/259206
0 comments