Telerik
Skip Navigation LinksHome / Community / Forums / ASP.NET > Grid > Export To CSV without header

Not answered Export To CSV without header

Feed from this thread
  • Tan avatar

    Posted on Oct 25, 2008 (permalink)

    Hello

    How can I export a RadGrid to CSV without the header row?

    I tried grid.ShowHeader = false, but it doesn't seem to affect the export.

    Does anyone has an idea?

    Regards,
    Andrea

    Reply

  • Tan avatar

    Posted on Oct 26, 2008 (permalink)

    Hi again

    I've got a couple more problems with the export to CSV:

    1) Data is automatically enclosed in double-quotes ("); how can I remove them?
    2) FileExtension property doesn't work properly. If I enter it as "csv", it's ignored, if I enter ".csv" it adds the dot and my filename looks like "Export..csv"
    3) header is exported; how can I remove that?

    Here's the complete code:

    gridExport.ShowHeader =

    false;
    gridExport.ExportSettings.ExportOnlyData =
    true;
    gridExport.ExportSettings.Csv.ColumnDelimiter =
    GridCsvDelimiter.Semicolon;
    gridExport.ExportSettings.Csv.RowDelimiter =
    GridCsvDelimiter.NewLine;
    gridExport.ExportSettings.Csv.FileExtension =
    "csv";

     

    gridExport.MasterTableView.ExportToCSV();

    Does anyone have a solution/ ideas?


    Regards,
    Andrea


    P.S.: I'm working since quite some time already with the RadControls and I really love them! But this CSV export seems to me quite  buggy (also when looking at older forum post).
    Dear Telerik team, please test that carefully.

     

    Reply

  • Telerik Admin admin's avatar

    Posted on Oct 28, 2008 (permalink)

    Hi Andrea,

    Regarding the double quotes, unfortunately in the classic version of RadGrid there is nothing you can do to remove them. In the Asp.Net Ajax version you can use the GridExporting event handler to modify the output data.

    The second issue seems to be a bug and I have forwarded it to our developers. Your Telerik points are updated for notifying us about it.

    As for the header, it cannot be removed when exporting to CSV which is a limitation with this kind of export. Please excuse us for any inconveniences.

    Greetings,
    Pavel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • Posted on May 20, 2009 (permalink)

    when you solve this issue regarding header export problem please reply as soon as possible. i download new version 2009 but still that problem is not solved why?

    Reply

  • Telerik Admin admin's avatar

    Posted on May 21, 2009 (permalink)

    Hello Hiren Savjiyani,

    The export to CSV does not allow automatic removal of the grid's header. In order to achieve this, you need to attach an event handler to the OnGridExporting event and parse the e.ExportOutput string object, removing the header text, which is straightforward to do.

    I hope this information helps.

    Best Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Posted on May 21, 2009 (permalink)

    please send me example for that.

    Reply

  • Posted on May 21, 2009 (permalink)

    hey i find solution for that. following method is the  easiest way to export data table to csv format with out header or with header.
    Example : -

    just copy paste this function.

    1st Parameter : datatable (Same datatable while you bind that grid)
    2nd Parameter : file path where you can save your file.

    public void CreateCSVFile(DataTable dt, string strFilePath)
        {
            #region Export Grid to CSV
            // Create the CSV file to which grid data will be exported.
            StreamWriter sw = new StreamWriter(strFilePath, false);
            // First we will write the headers.
            //DataTable dt = m_dsProducts.Tables[0];
            int iColCount = dt.Columns.Count;
            //for (int i = 0; i < iColCount; i++)
            //{
            //    sw.Write(dt.Columns[i]);
            //    if (i < iColCount - 1)
            //    {
            //        sw.Write(",");
            //    }
            //}

            //sw.Write(sw.NewLine);
            // Now write all the rows.
            foreach (DataRow dr in dt.Rows)
            {
                for (int i = 0; i < iColCount; i++)
                {
                    if (!Convert.IsDBNull(dr[i]))
                    {
                        sw.Write(dr[i].ToString());
                    }

                    if (i < iColCount - 1)
                    {

                        sw.Write(",");
                    }

                }
                sw.Write(sw.NewLine);

            }
            sw.Close();

            //System.IO.FileInfo info = new System.IO.FileInfo(strFilePath);
            Response.Clear();
            Response.ContentType = "application/x-csv";
            Response.AddHeader("Content-Disposition", "attachment;filename=User.csv");
            Response.TransmitFile(strFilePath);
            Response.End();

            #endregion

        }

    Reply

  • Telerik Admin admin's avatar

    Posted on May 21, 2009 (permalink)

    Hi Hiren,

    This is a viable solution, however, it is more difficult and time-consuming to implement.

    Please, find attached to this post a sample that demonstrates how to trim the gird's header when exporting to csv.

    Best Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Attached files

    Reply

  • Posted on May 26, 2009 (permalink)

    Thanks for that

    Reply

  • Posted on May 26, 2009 (permalink)

    yes that's good solutions but i m not able to find gridexport event in old grid but its working fine in new version.
    thanks again.

    Reply

  • Telerik Admin admin's avatar

    Posted on May 28, 2009 (permalink)

    Hi Hiren Savjiyani,

    Indeed, this scenario is not possible with the old version of the grid.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

Back to Top

Skip Navigation LinksHome / Community / Forums / ASP.NET > Grid > Export To CSV without header

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.