0
votes

I'm trying to export RadGrid data in zip format. For this, first I'm exporting data in Excel format and then I'm trying to compress it. But the return type for the method RadGrid.MasterTableView.ExportToExcel() is void so I cannot store this Excel sheet's result in order to pass it as input to ZipPackage.

2
Can't you create a stream from export method and then use telerik own zip control to grab stream and zip it? - TheTiger
you are saying that to create stream from ExporttoExcel method but I an unable to create stream from ExporttoExcel method - user2864496

2 Answers

0
votes

As far as I know Radgrid does not have a Zip export method. What you can do is: export the file in excel and then zip the excel file (or any other type you have exported). This is how I would do it:

 protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
    {
        //column you may like to excluded from the export process
        if (col.UniqueName.Contains("EditCommandColumn") ||
            col.UniqueName.Contains("attachments") ||
            col.UniqueName.Contains("Upload") || col.UniqueName.Contains("Delete_col"))
        {
            col.Display = false;
        }
        else
        {
            col.Display = true;
        }

    }
    foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
        item.Visible = false;
    RadGrid1.ExportSettings.ExportOnlyData = true;
    RadGrid1.ExportSettings.FileName = "YourDesiredFileName";
    RadGrid1.MasterTableView.ExportToExcel(); //this will be exported to the folder Download
    Zip();
}

private void Zip()
{
    //here your method with your preferred library to zip the file exported from the radgrid
    //save it where you need it, rename it as you like it and delete the original excel file
}
0
votes

I believe you could try hooking into the OnGridExporting command and then do something like this

   using (FileStream fs = File.Create("path you want to save the file")) {
            Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
            //save it on the server
            fs.Write(info, 0, info.Length);
        }

put all of this in a try , catch to watch for file permission problems and file already exists issues.