0

hi,
when i try to run the procedure below to export the gridview1 to msword,nothing appears on the document except tags <div> </div>.anyone knows what i might be doing wrong?

Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
   
      ' Verifies that the control is rendered
  
      End Sub
   
       
   
         Protected Sub ButtonExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonExport.Click
         Response.Clear()
         Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment;filename=HoursExport.doc")
        Response.Charset = ""
        Response.ContentType = "application/vnd.msword"
        Dim sw As New StringWriter()
        Dim hw As New HtmlTextWriter(sw)
        GridView1.AllowPaging = False
        GridView1.DataBind()
        GridView1.RenderControl(hw)
        Response.Output.Write(sw.ToString())
        Response.Flush()
        Response.[End]()
      
  
      End Sub

any assistance will be appreciated.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by tariqi
0

The below code works for me, Can you set content encoding and also can you ensure that MS word is installed on the client side.

Response.Clear();
Response.Buffer = true;

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

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

Edited by Ezzaral: Snipped &quot;fake sig&quot; link. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.

0

Hi,

Still not working,it just shows the <div> </div> tags in word,any other ideas?
i assign a data source to the gridview in code during execution,could that be the cause?

0

oh,sory your solution worked,i just removed gridview1.databind(),thanks alot

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.