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

ExportToPdf(), without opening the file

1 Answer 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen asked on 05 Dec 2012, 12:15 PM
I have a grid, and I want to export it to pdf and attach the file to an e-mail.

It seems like after calling ExportToPdf() the file is always opened. Is it possible to just save the pdf without opening it first?


Regards, Jill-Connie Lorentsen

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Dec 2012, 09:46 AM
Hello Jill-Connie Lorentsen,

You can save the file on the server and then attach it as per your requirements. Simple code-snippet is shown below:
protected void RadGrid1_GridExporting(object sender, GridExportingArgs e)
{
    using (FileStream fs = new FileStream(localPath, FileMode.Create))
    {
        byte[] bytes = Encoding.GetEncoding(1252).GetBytes(e.ExportOutput);
        fs.Write(bytes, 0, bytes.Length);
    }
    Response.Redirect(Request.RawUrl);
}

Note that you have to refresh the page if you prefer not to allow the file reach the client.

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jill-Connie Lorentsen
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or