locked
Need Help Exporting Gridview to RTF file for download RRS feed

  • Question

  • User547378418 posted

    I need help exporting Gridview to RTF file for download.

    I need a way to generate a report and export the results to a rtf file. I have found a lot of how-to's on exporting to PDF but I can't find anything on rtf.


    Please help me by example or point me to a good resource.


    Thank you in advance.

    J

    Tuesday, September 29, 2009 8:44 AM

Answers

All replies

  • User-955326108 posted

     Hello,

     

    If you combine this:

    http://itextsharp.sourceforge.net/tutorial/ch08.html

    and this:

    http://www.aspsnippets.com/post/2009/03/14/Export-GridView-To-WordExcelPDFCSV-in-ASPNet.aspx

    Then you'll achieve what you want to do.

     

    Cheers!

    /Eskil

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 29, 2009 8:57 AM
  • User312496708 posted

    Protected Sub Button1_Click(sender As Object, e As EventArgs)

    Response.Clear()
    Response.Buffer = True

    Response.AddHeader("content-disposition", "attachment;filename=FileName.doc")

    Response.ContentEncoding = System.Text.Encoding.UTF7
    Response.ContentType = "application/vnd.word"
    Dim oStringWriter As New System.IO.StringWriter()
    Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
    Me.GridView1.RenderControl(oHtmlTextWriter)
    Response.Output.Write(oStringWriter.ToString())
    Response.Flush()
    Response.End()

    End Sub

    Tuesday, September 29, 2009 8:57 AM
  • User547378418 posted

    Now I only need to know how to write more than one GridView (lets say Gridview1, GridView2 and GridView3), to the same file.


    Do I just repeat:


            GridView1.AllowPaging = false;
            GridView1.DataBind();
            GridView1.RenderControl(hw);
            Response.Output.Write(sw.ToString());
    
            GridView2.AllowPaging = false;
            GridView2.DataBind();
            GridView2.RenderControl(hw);
            Response.Output.Write(sw.ToString());
    
            GridView3.AllowPaging = false;
            GridView3.DataBind();
            GridView3.RenderControl(hw);
            Response.Output.Write(sw.ToString());
    




    and

    Response.Flush(); Response.End();


    when done?

    Wednesday, September 30, 2009 5:35 AM
  • User547378418 posted

    also,

    I had to include:

    <%@ Page EnableEventValidation="False" %>

    on the aspx page. Is there a way to change this validation to false in the code behind and then back to true when done?


    Wednesday, September 30, 2009 5:40 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 30, 2009 5:52 AM
  • User547378418 posted

    Thanks everyone. Those links provided great information.

    This was also needed....


        protected void ExportWord_Button_Click(object sender, EventArgs e)
        {   
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc");
            Response.Charset = "";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("Windows-1252");
            Response.ContentType = "application/vnd.ms-word ";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.AllowPaging = false;
            GridView1.DataBind();
            GridView1.RenderControl(hw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
    
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            /* Verifies that the control is rendered */
        }
    
    
    
    
    
    
    ///  was used on the aspx page, but wish there was a way to set/reset this in the code behind
    <%@ Page EnableEventValidation="False" 


    Thursday, October 1, 2009 7:35 AM