Email exported pdf from grid

4 posts, 0 answers
  1. Vatsal
    Vatsal avatar
    26 posts
    Member since:
    Oct 2010

    Posted 20 Sep 2012 Link to this post

    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
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 20 Sep 2012 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vatsal
    Vatsal avatar
    26 posts
    Member since:
    Oct 2010

    Posted 20 Sep 2012 Link to this post

    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
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 20 Sep 2012 Link to this post

    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
Back to Top