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

Email exported pdf from grid

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vatsal
Top achievements
Rank 2
Vatsal asked on 20 Sep 2012, 12:42 PM
Hi,

I have rad grid in my page and have running functionality of export to pdf also. Now I want to email that exported pdf to multiple persons, from code behind. I have context menu in grid and with option "Send Email" so when user click this option email should be generated automatically so that I can send it using SMTP.

Can you please help me in this? It's urgent for me.

Thanks,
Vatsal

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Sep 2012, 01:00 PM
Hello,

protected void RadGrid1_GridExporting(object sender, GridExportingArgs e)
  {
      string path = Server.MapPath("~/" + Guid.NewGuid() + ".pdf");
 
      using (FileStream fs = File.Create(path))
      {
          Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
          fs.Write(info, 0, info.Length);
      }
 
      //path -- Your send mail logic somes here
 
      Response.Redirect(Request.Url.ToString());
 
       
  }


Thanks,
Jayesh Goyani
0
Vatsal
Top achievements
Rank 2
answered on 20 Sep 2012, 02:02 PM
Hi Jayesh,

Thanks for your reply.

Is there any way where I can only send email. Currently it's showing popup for open / Save exported document too. I don't want to show that popup.

Thanks again,
Vatsal
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Sep 2012, 05:02 PM
Hello,

I have tried with below code and it works correctly from my side.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
         
           
            OnGridExporting="RadGrid1_GridExporting">
            <MasterTableView CommandItemDisplay="Top" >
                <CommandItemSettings ShowExportToPdfButton="true" />
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
                   
                </Columns>
            </MasterTableView>
             
        </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
              new { ID = 1, Name ="aaa"},
              new { ID = 2, Name = "bbb"},
              new { ID = 3, Name = "ccc"},
              new { ID = 4, Name = "ddd"},
               new { ID = 5, Name ="eee"}
            };
            RadGrid1.DataSource = data;
        }
 
protected void RadGrid1_GridExporting(object sender, GridExportingArgs e)
        {
            string path = Server.MapPath("~/" + Guid.NewGuid() + ".pdf");
 
            using (FileStream fs = File.Create(path))
            {
                Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
                fs.Write(info, 0, info.Length);
            }
 
            // Your send mail logic somes here
 
            Response.Redirect(Request.Url.ToString());
        }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Vatsal
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Vatsal
Top achievements
Rank 2
Share this question
or