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

ExportSettings.FileName replacing space with +

6 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sf
Top achievements
Rank 1
sf asked on 22 Jul 2010, 05:08 AM
in my code behind I do this:
RadGrid1.ExportSettings.FileName = "This is a report export file generated in " + DateTime.Now.Year.ToString();

at runtime the exported file name becomes "This+is+a+report+export+file+generated+in+2010"


am I doing something wrong?

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Jul 2010, 02:43 PM
Hello SF,

I'm afraid this is browser-specific behavior. Please try another browser - IE7, Firefox, Opera, etc and let me know whether the problem still persists.

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lubna Ansari
Top achievements
Rank 1
answered on 28 Jul 2010, 09:24 AM
Hi Daniel,

Firefox is working fine but IE7 is having the same problem.
0
Daniel
Telerik team
answered on 28 Jul 2010, 10:19 AM
Hello Lubna,

The file name is encoded as UTF-8 string and this causes Internet Explorer 8 to interpret the whitespace characters as pluses. If you sidestep this functionality (it is possible) you won't be able to use non-US characters in the file name.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
treesara
Top achievements
Rank 1
answered on 04 Nov 2010, 06:27 PM
How would one sidestep this encoding?
0
Daniel
Telerik team
answered on 07 Nov 2010, 03:10 PM
Hello Treesara,

Please try the following approach:
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    if (e.ExportType == ExportType.Excel)
    {
        string filename = RadGrid1.ExportSettings.FileName;
        string fileExtension = RadGrid1.ExportSettings.Excel.FileExtension;
 
        this.Response.ClearHeaders();
        this.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "." + fileExtension + "\"");
    }
}

Kind regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vasssek
Top achievements
Rank 1
answered on 21 Apr 2015, 12:15 PM

Hi,

here is another solution.

protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
    {
        if (e.ExportType == ExportType.Excel || e.ExportType == ExportType.ExcelML || e.ExportType == ExportType.ExcelXlsx || e.ExportType == ExportType.ExcelBiff)
        {
            string filename = RadGrid1.ExportSettings.FileName;
            string fileExtension = RadGrid1.ExportSettings.Excel.FileExtension;
            var headerValue = (Request.UserAgent.ToLower().Contains("msie")) ? string.Format("attachment; filename=\"{0}\"", Uri.EscapeDataString(filename + "." + fileExtension)) : string.Format("attachment; filename=\"{0}\"", filename + "." + fileExtension); //for Firefox, Chrome, Safari, Opera
 
            this.Response.ClearHeaders();
            this.Response.AddHeader("Content-Disposition", headerValue);
        }
    }

This way, you can have also filenames with UTF8 characters (spaces, diacritics...)

Best regards

Vasssek

Tags
Grid
Asked by
sf
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Lubna Ansari
Top achievements
Rank 1
treesara
Top achievements
Rank 1
Vasssek
Top achievements
Rank 1
Share this question
or