ExportSettings.FileName replacing space with +

7 posts, 0 answers
  1. sf
    sf avatar
    103 posts
    Member since:
    Apr 2009

    Posted 22 Jul 2010 Link to this post

    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?
  2. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 22 Jul 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 28 Jul 2010 Link to this post

    Hi Daniel,

    Firefox is working fine but IE7 is having the same problem.
  5. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 28 Jul 2010 Link to this post

    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
  6. treesara
    treesara avatar
    11 posts
    Member since:
    Aug 2006

    Posted 04 Nov 2010 Link to this post

    How would one sidestep this encoding?
  7. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 07 Nov 2010 Link to this post

    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
  8. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 21 Apr 2015 in reply to Daniel Link to this post

    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

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017