Pls, somebody help me on writting a code to create word file from my c# form...

saguni commented: Kindly quote the type of application which u are developing... +0
commented: pls, can you help me.. have done the one for .txt but my c# form has got a .jpg picture that i want it to show in the file... +0

Word files is not as easy as to write a text to a .txt file. You need an Office open XML API to write create a word file. Here is a link to the API:

Click Here

commented: pls, can you help me.. have done the one for .txt but my c# form has got a .jpg picture that i want it to show in the file... +0

there is an really good tutorial with all the steps on this webpage:
Click Here

commented: hmmm!!! thanks, i think this should work... +0

You can also use the following code...

            SqlCommand cmd = new SqlCommand("select * from sps_login", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            con.Close();
            GridView1.DataSource = ds;
            GridView1.DataBind();

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc");
            Response.Charset = "";
            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();

Hope it helps you...

Have a happy coding...:-D

commented: no, it's not helping i need to create microsoft word file.... +0

Are you developing a windows application or web application? @timmyjoshua

I am asking that because, I also used the similiar code as @ss125 posted in the above post. Its used for the web application. If you want a windows application code, you have to mention that in your question itself.

commented: yes, i see it not dsame.. i'm developing windows app... +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.