• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

Convert DataGrid To msWord C#

Hi,
 How do I convert DataGrid to ms Word (C#) and save the word file.


thnx
0
madmare
Asked:
madmare
  • 2
1 Solution
 
Sammy AgeilCommented:
0
 
mangesh004Commented:
Hi,

IN C#
-------------------------------------------------------------
protected void Button1_Click(object sender, System.EventArgs e)
{
 Response.Clear();
 Response.AddHeader("content-disposition", "attachment;filename=QuestionList.doc");
 Response.Charset = "";
 Response.Cache.SetCacheability(HttpCacheability.NoCache);
 Response.ContentType = "application/vnd.word";
 System.IO.StringWriter tw = new System.IO.StringWriter();
 System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
 gvQuestionList.RenderControl(hw);
 Response.Write(tw.ToString());
 Response.End();
}
-------------------------------------------------------------

In VB:
-------------------------------------------------------------
  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Clear()
        Response.AddHeader("content-disposition", "attachment;filename=QuestionList.doc")
        Response.Charset = ""
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = "application/vnd.word"
        'Response.ContentType = "application/vnd.ms-excel"
        '' Remove the charset from the Content-Type header.
        'Response.Charset = ""
        '' Turn off the view state.
        'Me.EnableViewState = False
        Dim tw As New System.IO.StringWriter
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        ' Get the HTML for the control.
        gvQuestionList.RenderControl(hw)
        ' Write the HTML back to the browser.
        Response.Write(tw.ToString())
        ' End the response.
        Response.End()

    End Sub

-------------------------------------------------------------

Conversion done using : http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

I used the vb.net code then converted into C# .... Please correct the errors if you are getting any

Regards,
Mangesh
0
 
mangesh004Commented:
Forgot to mention

Change the grid name from gvQuestionList to the required one

Regards,
Mangesh
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now