Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have downloaded html editor from How to Create an HTML Editor for ASP.NET AJAX[^] and it is working fine... now i want to download a word file using contents of that editor... i have tried code and also search on google but in wain.. please help me... Thanks in advance...
Posted
Updated 14-Jul-12 1:54am
v3
Comments
[no name] 14-Jul-12 7:46am    
What? Code? What code? "download a word file using contents of that editor"... makes no sense at all.
Sebastian T Xavier 14-Jul-12 7:55am    
"now I want to download a word file ......."!!!! are you from mars?
Sandeep Mewara 14-Jul-12 12:26pm    
Share your effort.

1 solution

Hello,

There is a very easy way to do that.

Just get the HTML created in this control and put it inside an HTML tag with the mime type set to "application/msword", then just save as a .Doc file. Don't use .Docx as it won't work.

It won't create a real Word document, but Word will understand it, load it and render it properly, and from a user point of view it makes no difference.

XML
<html type="application/msword">

<h1>Heading 1</h1>
<p>This text is <strong>bold</strong>, this <em>italic</em>, and this <span style="text-decoration: underline">underlined</span>.</p>
<div dir="ltr" style="margin-left: 40px"><div dir="ltr" style="margin-left: 40px"><div dir="ltr" style="margin-left: 40px"><div dir="ltr" style="margin-left: 40px"><p>This text is <span style="font-family: Arial">Arial</span>, this <span style="font-family: Garamond">Garamond</span>, and this <span style="font-family: Verdana">Verdana</span>.</p></div></div></div></div>
<ul>
<li>Bullet 1 </li>
<li>Bullet 2</li>
</ul>

</html>



Valery.
 
Share this answer
 
v2
Comments
Naikniket 15-Jul-12 7:24am    
i have tried it, but not working... may be i am not able to understand it properly... can you please explain in detail...???
Naikniket 15-Jul-12 7:26am    
when i download the word file it will download but if i write HI in bold fontes in editor, then in word file it will display as html code only as we write in html to make font bold...
Valery Possoz 15-Jul-12 17:53pm    
Hi,

I've just tried the only demo of the editor and type the following html code in it : <strong>Hi</strong>

I then modify this text (not in the editor, in my code...) so that it looks like that:

<html type="application/msword">
<strong>Hi</strong>
</html>

Save that as Test.Doc, and open in word, it renders correctly, everything is fine in Word.

Could you describe your issue with more details please, maybe show some code?

Valery.
Naikniket 16-Jul-12 0:25am    
i have placed one more button in this application, named "save as word file". Now i have placed this code,

HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=document.doc");
StringBuilder strHTMLContent = new StringBuilder();

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";

strHTMLContent.Append(Edit.text);//Edit.Text is the contents of the html editor

HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();

this is giving me contents with html code.
Naikniket 16-Jul-12 0:42am    
i have tried this also..


Response.Clear();

Response.Buffer = true;

Response.ContentType = "application/msword";

Response.AddHeader("Content-Disposition", "inline;filename=MyDoc.doc");

StringBuilder myBuilder = new StringBuilder();


myBuilder.Append("< html type='application/msword'>");

myBuilder.Append(Edit.Text);


myBuilder.Append("< /html>");

Response.Write(myBuilder);
Response.End();
Response.Flush();

it is giving me output like this...
< html type='application/msword'>Hi < /html>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900