How to convert .aspx file to word file usign C# asp.net

Posted by Mahe under C# on 7/19/2012 | Points: 10 | Views : 13144 | Status : [Member] | Replies : 2
Hi,

How to convert .aspx file to word file usign C# asp.net ?


Regards,
Mahe




Responses

Posted by: Megan00 on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
You can save it as html file and convert html to word document by blelow code:
            Document document = new Document();

document.LoadFromFile(@"E:\TestScript\Word to HTML\Word to HTML\bin\Debug\Sample.html", FileFormat.Html, XHTMLValidationType.None);
document.SaveToFile("test.doc", FileFormat.Doc);


but you need to download Spire.Doc first: http://www.e-iceblue.com/Download/download-word-for-net-now.html



Never give up! Smile to the world!
http://excelcsharp.blog.com/

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sebas on: 6/12/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
You can use Elerium HTML to Word .NET converter to convert .aspx page to word document. But it is not free.

//Save .aspx page from itself
StringWriter objStringWriter = new StringWriter();
HtmlTextWriter objHtmlWriter = new HtmlTextWriter(objStringWriter);
Page.RenderControl(objHtmlWriter);
string html = objStringWriter.ToString();
Document doc = Document.ReadHTML(html);
doc.WriteDOCX(@"c:\report.docx")
//Save .aspx page by url
string url = "http:/www.somesite.com/product.aspx";
WebClient client = new WebClient ();
Stream data = client.OpenRead (url);
StreamReader reader = new StreamReader (data);
string shtml = reader.ReadToEnd ();
data.Close ();
reader.Close ();
Document doc = Document.ReadHTML(shtml);
doc.WriteDOCX(@"c:\report.docx")

link to component: http://eleriumsoft.com/Word_NET/HTML2WORD/Default.aspx

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response